Assert\Assertion::url PHP Метод

url() публичный статический Метод

This code snipped was taken from the Symfony project and modified to the special demands of this method.
public static url ( mixed $value, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$message string | null
$propertyPath string | null
Результат boolean
    public static function url($value, $message = null, $propertyPath = null)
    {
        static::string($value, $message, $propertyPath);
        $protocols = array('http', 'https');
        $pattern = '~^
            (%s)://                                 # protocol
            (([\\pL\\pN-]+:)?([\\pL\\pN-]+)@)?          # basic auth
            (
                ([\\pL\\pN\\pS-\\.])+(\\.?([\\pL\\pN]|xn\\-\\-[\\pL\\pN-]+)+\\.?) # a domain name
                    |                                                 # or
                \\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}                    # an IP address
                    |                                                 # or
                \\[
                    (?:(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-f]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,1}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,2}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,3}(?:(?:[0-9a-f]{1,4})))?::(?:(?:[0-9a-f]{1,4})):)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,4}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,5}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,6}(?:(?:[0-9a-f]{1,4})))?::))))
                \\]  # an IPv6 address
            )
            (:[0-9]+)?                              # a port (optional)
            (/?|/\\S+|\\?\\S*|\\#\\S*)                   # a /, nothing, a / with something, a query or a fragment
        $~ixu';
        $pattern = sprintf($pattern, implode('|', $protocols));
        if (!preg_match($pattern, $value)) {
            $message = sprintf($message ?: 'Value "%s" was expected to be a valid URL starting with http or https', static::stringify($value));
            throw static::createException($value, $message, static::INVALID_URL, $propertyPath);
        }
        return true;
    }

Usage Example

 /**
  * IssuerDiscoveryEndpoint constructor.
  *
  * @param \OAuth2\UserAccount\UserAccountManagerInterface $user_account_manager
  * @param \OAuth2\Exception\ExceptionManagerInterface     $exception_manager
  * @param string                                          $issuer               The issuer of the resource
  * @param string                                          $server               The server URI of this discovery service
  */
 public function __construct(UserAccountManagerInterface $user_account_manager, ExceptionManagerInterface $exception_manager, $issuer, $server)
 {
     Assertion::url($issuer, 'The issuer must be an URL.');
     Assertion::url($server, 'The server must be an URL.');
     $this->setUserAccountManager($user_account_manager);
     $this->setExceptionManager($exception_manager);
     $this->setIssuer($issuer);
     $this->computed_server = $this->getDomain($server);
 }
All Usage Examples Of Assert\Assertion::url