Url.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Validator\Constraints;
  11. use Symfony\Component\Validator\Constraint;
  12. use Symfony\Component\Validator\Exception\InvalidArgumentException;
  13. /**
  14. * @Annotation
  15. * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
  16. *
  17. * @author Bernhard Schussek <bschussek@gmail.com>
  18. */
  19. #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
  20. class Url extends Constraint
  21. {
  22. public const INVALID_URL_ERROR = '57c2f299-1154-4870-89bb-ef3b1f5ad229';
  23. protected static $errorNames = [
  24. self::INVALID_URL_ERROR => 'INVALID_URL_ERROR',
  25. ];
  26. public $message = 'This value is not a valid URL.';
  27. public $protocols = ['http', 'https'];
  28. public $relativeProtocol = false;
  29. public $normalizer;
  30. public function __construct(
  31. array $options = null,
  32. string $message = null,
  33. array $protocols = null,
  34. bool $relativeProtocol = null,
  35. callable $normalizer = null,
  36. array $groups = null,
  37. $payload = null
  38. ) {
  39. parent::__construct($options, $groups, $payload);
  40. $this->message = $message ?? $this->message;
  41. $this->protocols = $protocols ?? $this->protocols;
  42. $this->relativeProtocol = $relativeProtocol ?? $this->relativeProtocol;
  43. $this->normalizer = $normalizer ?? $this->normalizer;
  44. if (null !== $this->normalizer && !\is_callable($this->normalizer)) {
  45. throw new InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', get_debug_type($this->normalizer)));
  46. }
  47. }
  48. }