| Conditions | 4 |
| Paths | 4 |
| Total Lines | 24 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 32 | public function validate($value, Constraint $constraint) |
||
| 33 | { |
||
| 34 | if (!$constraint instanceof Enum) { |
||
| 35 | throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Enum'); |
||
| 36 | } |
||
| 37 | |||
| 38 | $constraint->choices = null; |
||
| 39 | $constraint->callback = null; |
||
| 40 | |||
| 41 | if (!$constraint->enum) { |
||
| 42 | throw new ConstraintDefinitionException('"enum" must be specified on constraint Enum'); |
||
| 43 | } |
||
| 44 | |||
| 45 | if (!$this->enumRegistry->has($constraint->enum)) { |
||
| 46 | throw new ConstraintDefinitionException(sprintf( |
||
| 47 | '"enum" "%s" on constraint Enum does not exist', |
||
| 48 | $constraint->enum |
||
| 49 | )); |
||
| 50 | } |
||
| 51 | |||
| 52 | $constraint->choices = array_keys($this->enumRegistry->get($constraint->enum)->getChoices()); |
||
| 53 | |||
| 54 | parent::validate($value, $constraint); |
||
| 55 | } |
||
| 56 | } |
||
| 57 |