Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Url.php

class Url

Same name in this branch
  1. 11.1.x vendor/phar-io/manifest/src/values/Url.php \PharIo\Manifest\Url
  2. 11.1.x vendor/composer/composer/src/Composer/Util/Url.php \Composer\Util\Url
  3. 11.1.x vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Reference/Url.php \phpDocumentor\Reflection\DocBlock\Tags\Reference\Url
  4. 11.1.x core/lib/Drupal/Core/Url.php \Drupal\Core\Url
  5. 11.1.x core/lib/Drupal/Core/Render/Element/Url.php \Drupal\Core\Render\Element\Url
  6. 11.1.x core/modules/views/src/Plugin/views/field/Url.php \Drupal\views\Plugin\views\field\Url

Validates that a value is a valid URL string.

@author Bernhard Schussek <bschussek@gmail.com>

Hierarchy

  • class \Symfony\Component\Validator\Constraint
    • class \Symfony\Component\Validator\Constraints\Url extends \Symfony\Component\Validator\Constraint

Expanded class hierarchy of Url

81 string references to 'Url'
ArgumentPluginBase::getCacheContexts in core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php
The cache contexts associated with this object.
Auditor::outputAdvisoriesTable in vendor/composer/composer/src/Composer/Advisory/Auditor.php
BuildInformation::setRuntimeInformation in vendor/phpunit/php-code-coverage/src/Report/Xml/BuildInformation.php
claro_preprocess_input in core/themes/claro/claro.theme
Implements template_preprocess_HOOK() for input.
CommentTokensHooks::tokenInfo in core/modules/comment/src/Hook/CommentTokensHooks.php
Implements hook_token_info().

... See full list

File

vendor/symfony/validator/Constraints/Url.php, line 22

Namespace

Symfony\Component\Validator\Constraints
View source
class Url extends Constraint {
    public const INVALID_URL_ERROR = '57c2f299-1154-4870-89bb-ef3b1f5ad229';
    public const MISSING_TLD_ERROR = '8a5d387f-0716-46b4-844b-67367faf435a';
    protected const ERROR_NAMES = [
        self::INVALID_URL_ERROR => 'INVALID_URL_ERROR',
        self::MISSING_TLD_ERROR => 'MISSING_TLD_ERROR',
    ];
    public string $message = 'This value is not a valid URL.';
    public string $tldMessage = 'This URL is missing a top-level domain.';
    public array $protocols = [
        'http',
        'https',
    ];
    public bool $relativeProtocol = false;
    public bool $requireTld = false;
    
    /** @var callable|null */
    public $normalizer;
    
    /**
     * @param array<string,mixed>|null $options
     * @param string[]|null            $protocols        The protocols considered to be valid for the URL (e.g. http, https, ftp, etc.) (defaults to ['http', 'https']
     * @param bool|null                $relativeProtocol Whether to accept URL without the protocol (i.e. //example.com) (defaults to false)
     * @param string[]|null            $groups
     * @param bool|null                $requireTld       Whether to require the URL to include a top-level domain (defaults to false)
     */
    public function __construct(?array $options = null, ?string $message = null, ?array $protocols = null, ?bool $relativeProtocol = null, ?callable $normalizer = null, ?array $groups = null, mixed $payload = null, ?bool $requireTld = null, ?string $tldMessage = null) {
        parent::__construct($options, $groups, $payload);
        if (null === ($options['requireTld'] ?? $requireTld)) {
            trigger_deprecation('symfony/validator', '7.1', 'Not passing a value for the "requireTld" option to the Url constraint is deprecated. Its default value will change to "true".');
        }
        $this->message = $message ?? $this->message;
        $this->protocols = $protocols ?? $this->protocols;
        $this->relativeProtocol = $relativeProtocol ?? $this->relativeProtocol;
        $this->normalizer = $normalizer ?? $this->normalizer;
        $this->requireTld = $requireTld ?? $this->requireTld;
        $this->tldMessage = $tldMessage ?? $this->tldMessage;
        if (null !== $this->normalizer && !\is_callable($this->normalizer)) {
            throw new InvalidArgumentException(\sprintf('The "normalizer" option must be a valid callable ("%s" given).', get_debug_type($this->normalizer)));
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
Constraint::$groups public property The groups that the constraint belongs to.
Constraint::$payload public property Domain-specific data attached to a constraint.
Constraint::addImplicitGroupName public function Adds the given group if this constraint is in the Default group. 2
Constraint::CLASS_CONSTRAINT public constant Marks a constraint that can be put onto classes.
Constraint::DEFAULT_GROUP public constant The name of the group given to all constraints with no explicit group.
Constraint::getDefaultOption public function Returns the name of the default option. 28
Constraint::getErrorName public static function Returns the name of the given error code.
Constraint::getRequiredOptions public function Returns the name of the required options. 22
Constraint::getTargets public function Returns whether the constraint can be put onto classes, properties or
both.
8
Constraint::normalizeOptions protected function
Constraint::PROPERTY_CONSTRAINT public constant Marks a constraint that can be put onto properties.
Constraint::validatedBy public function Returns the name of the class that validates this constraint. 9
Constraint::__get public function Returns the value of a lazily initialized option. 2
Constraint::__isset public function 1
Constraint::__set public function Sets the value of a lazily initialized option. 1
Constraint::__sleep public function Optimizes the serialized value to minimize storage space.
Url::$message public property
Url::$normalizer public property @var callable|null
Url::$protocols public property
Url::$relativeProtocol public property
Url::$requireTld public property
Url::$tldMessage public property
Url::ERROR_NAMES protected constant Maps error codes to the names of their constants. Overrides Constraint::ERROR_NAMES
Url::INVALID_URL_ERROR public constant
Url::MISSING_TLD_ERROR public constant
Url::__construct public function Overrides Constraint::__construct
RSS feed
Powered by Drupal