vendor/symfony/validator/Constraints/Choice.php line 23

Open in your IDE?
  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. /**
  13.  * @Annotation
  14.  * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
  15.  *
  16.  * @author Bernhard Schussek <bschussek@gmail.com>
  17.  */
  18. #[\Attribute(\Attribute::TARGET_PROPERTY \Attribute::TARGET_METHOD \Attribute::IS_REPEATABLE)]
  19. class Choice extends Constraint
  20. {
  21.     public const NO_SUCH_CHOICE_ERROR '8e179f1b-97aa-4560-a02f-2a8b42e49df7';
  22.     public const TOO_FEW_ERROR '11edd7eb-5872-4b6e-9f12-89923999fd0e';
  23.     public const TOO_MANY_ERROR '9bd98e49-211c-433f-8630-fd1c2d0f08c3';
  24.     protected static $errorNames = [
  25.         self::NO_SUCH_CHOICE_ERROR => 'NO_SUCH_CHOICE_ERROR',
  26.         self::TOO_FEW_ERROR => 'TOO_FEW_ERROR',
  27.         self::TOO_MANY_ERROR => 'TOO_MANY_ERROR',
  28.     ];
  29.     public $choices;
  30.     public $callback;
  31.     public $multiple false;
  32.     public $strict true;
  33.     public $min;
  34.     public $max;
  35.     public $message 'The value you selected is not a valid choice.';
  36.     public $multipleMessage 'One or more of the given values is invalid.';
  37.     public $minMessage 'You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.';
  38.     public $maxMessage 'You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.';
  39.     /**
  40.      * {@inheritdoc}
  41.      */
  42.     public function getDefaultOption()
  43.     {
  44.         return 'choices';
  45.     }
  46.     public function __construct(
  47.         $options = [],
  48.         array $choices null,
  49.         $callback null,
  50.         bool $multiple null,
  51.         bool $strict null,
  52.         int $min null,
  53.         int $max null,
  54.         string $message null,
  55.         string $multipleMessage null,
  56.         string $minMessage null,
  57.         string $maxMessage null,
  58.         $groups null,
  59.         $payload null
  60.     ) {
  61.         if (\is_array($options) && $options && array_is_list($options)) {
  62.             $choices $choices ?? $options;
  63.             $options = [];
  64.         }
  65.         if (null !== $choices) {
  66.             $options['value'] = $choices;
  67.         }
  68.         parent::__construct($options$groups$payload);
  69.         $this->callback $callback ?? $this->callback;
  70.         $this->multiple $multiple ?? $this->multiple;
  71.         $this->strict $strict ?? $this->strict;
  72.         $this->min $min ?? $this->min;
  73.         $this->max $max ?? $this->max;
  74.         $this->message $message ?? $this->message;
  75.         $this->multipleMessage $multipleMessage ?? $this->multipleMessage;
  76.         $this->minMessage $minMessage ?? $this->minMessage;
  77.         $this->maxMessage $maxMessage ?? $this->maxMessage;
  78.     }
  79. }