class UrlValidator in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/validator/Constraints/UrlValidator.php \Symfony\Component\Validator\Constraints\UrlValidator
@author Bernhard Schussek <bschussek@gmail.com>
Hierarchy
- class \Symfony\Component\Validator\ConstraintValidator implements ConstraintValidatorInterface
- class \Symfony\Component\Validator\Constraints\UrlValidator
Expanded class hierarchy of UrlValidator
1 file declares its use of UrlValidator
- UrlValidatorTest.php in vendor/
symfony/ validator/ Tests/ Constraints/ UrlValidatorTest.php
File
- vendor/
symfony/ validator/ Constraints/ UrlValidator.php, line 22
Namespace
Symfony\Component\Validator\ConstraintsView source
class UrlValidator extends ConstraintValidator {
const PATTERN = '~^
(%s):// # protocol
(([\\pL\\pN-]+:)?([\\pL\\pN-]+)@)? # basic auth
(
([\\pL\\pN\\pS-\\.])+(\\.?([\\pL]|xn\\-\\-[\\pL\\pN-]+)+\\.?) # a domain name
| # or
\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3} # a 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})))|(?:(?:(?:(?:(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:[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})))?::))))
\\] # a IPv6 address
)
(:[0-9]+)? # a port (optional)
(/?|/\\S+|\\?|\\#) # a /, nothing, a / with something, a query or a fragment
$~ixu';
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint) {
if (!$constraint instanceof Url) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\Url');
}
if (null === $value) {
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
$value = (string) $value;
if ('' === $value) {
return;
}
$pattern = sprintf(static::PATTERN, implode('|', $constraint->protocols));
if (!preg_match($pattern, $value)) {
if ($this->context instanceof ExecutionContextInterface) {
$this->context
->buildViolation($constraint->message)
->setParameter('{{ value }}', $this
->formatValue($value))
->addViolation();
}
else {
$this
->buildViolation($constraint->message)
->setParameter('{{ value }}', $this
->formatValue($value))
->addViolation();
}
return;
}
if ($constraint->checkDNS) {
$host = parse_url($value, PHP_URL_HOST);
if (!checkdnsrr($host, 'ANY')) {
if ($this->context instanceof ExecutionContextInterface) {
$this->context
->buildViolation($constraint->dnsMessage)
->setParameter('{{ value }}', $this
->formatValue($host))
->addViolation();
}
else {
$this
->buildViolation($constraint->dnsMessage)
->setParameter('{{ value }}', $this
->formatValue($host))
->addViolation();
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConstraintValidator:: |
protected | property | 3 | |
ConstraintValidator:: |
protected | function | Wrapper for {@link ExecutionContextInterface::buildViolation} that supports the 2.4 context API. | |
ConstraintValidator:: |
protected | function | Wrapper for {@link ExecutionContextInterface::buildViolation} that supports the 2.4 context API. | |
ConstraintValidator:: |
protected | function | Returns a string representation of the type of the value. | |
ConstraintValidator:: |
protected | function | Returns a string representation of the value. | |
ConstraintValidator:: |
protected | function | Returns a string representation of a list of values. | |
ConstraintValidator:: |
public | function |
Initializes the constraint validator. Overrides ConstraintValidatorInterface:: |
1 |
ConstraintValidator:: |
constant | Whether to cast objects with a "__toString()" method to strings. | ||
ConstraintValidator:: |
constant | Whether to format {@link \DateTime} objects as RFC-3339 dates ("Y-m-d H:i:s"). | ||
UrlValidator:: |
constant | |||
UrlValidator:: |
public | function |
Checks if the passed value is valid. Overrides ConstraintValidatorInterface:: |