Inheritance: extends Symfony\Component\Validator\Constraint
Example #1
0
 /**
  * {@inheritdoc}
  */
 public function __construct($options = null)
 {
     if (isset($options['entity'])) {
         /** @var AbstractEnumType $entity */
         $entity = $options['entity'];
         if (is_subclass_of($entity, 'Fresh\\DoctrineEnumBundle\\DBAL\\Types\\AbstractEnumType')) {
             $this->choices = $entity::getValues();
         }
     }
     parent::__construct($options);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function __construct($options = null)
 {
     if (isset($options['entity'])) {
         /** @var AbstractEnumType $entity */
         $entity = $options['entity'];
         if (is_a($entity, 'Fresh\\DoctrineEnumBundle\\DBAL\\Types\\AbstractEnumType', true)) {
             $this->choices = array_keys($entity::getChoices());
         }
     }
     parent::__construct($options);
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function __construct($options = null)
 {
     parent::__construct($options);
     if (!is_a($this->class, AbstractEnum::class, true)) {
         throw new ConstraintDefinitionException('The option "class" must be a class that inherits from ' . AbstractEnum::class);
     }
     $this->choices = call_user_func([$this->class, 'getConstants']);
     if ($this->showKeys) {
         $keysMessage = 'Valid ' . $this->class . ' constant keys are: ' . implode(', ', call_user_func([$this->class, 'getKeys'])) . '.';
         $this->message .= ' ' . $keysMessage;
         $this->multipleMessage .= ' ' . $keysMessage;
     }
 }