Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/validator/Constraints/ChoiceValidator.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
32 { | 32 { |
33 if (!$constraint instanceof Choice) { | 33 if (!$constraint instanceof Choice) { |
34 throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Choice'); | 34 throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Choice'); |
35 } | 35 } |
36 | 36 |
37 if (!is_array($constraint->choices) && !$constraint->callback) { | 37 if (!\is_array($constraint->choices) && !$constraint->callback) { |
38 throw new ConstraintDefinitionException('Either "choices" or "callback" must be specified on constraint Choice'); | 38 throw new ConstraintDefinitionException('Either "choices" or "callback" must be specified on constraint Choice'); |
39 } | 39 } |
40 | 40 |
41 if (null === $value) { | 41 if (null === $value) { |
42 return; | 42 return; |
43 } | 43 } |
44 | 44 |
45 if ($constraint->multiple && !is_array($value)) { | 45 if ($constraint->multiple && !\is_array($value)) { |
46 throw new UnexpectedTypeException($value, 'array'); | 46 throw new UnexpectedTypeException($value, 'array'); |
47 } | 47 } |
48 | 48 |
49 if ($constraint->callback) { | 49 if ($constraint->callback) { |
50 if (!is_callable($choices = array($this->context->getObject(), $constraint->callback)) | 50 if (!\is_callable($choices = [$this->context->getObject(), $constraint->callback]) |
51 && !is_callable($choices = array($this->context->getClassName(), $constraint->callback)) | 51 && !\is_callable($choices = [$this->context->getClassName(), $constraint->callback]) |
52 && !is_callable($choices = $constraint->callback) | 52 && !\is_callable($choices = $constraint->callback) |
53 ) { | 53 ) { |
54 throw new ConstraintDefinitionException('The Choice constraint expects a valid callback'); | 54 throw new ConstraintDefinitionException('The Choice constraint expects a valid callback'); |
55 } | 55 } |
56 $choices = call_user_func($choices); | 56 $choices = \call_user_func($choices); |
57 } else { | 57 } else { |
58 $choices = $constraint->choices; | 58 $choices = $constraint->choices; |
59 } | 59 } |
60 | 60 |
61 if (true !== $constraint->strict) { | 61 if (true !== $constraint->strict) { |
62 @trigger_error('Not setting the strict option of the Choice constraint to true is deprecated since Symfony 3.4 and will throw an exception in 4.0.', E_USER_DEPRECATED); | 62 @trigger_error('Not setting the strict option of the Choice constraint to true is deprecated since Symfony 3.4 and will throw an exception in 4.0.', E_USER_DEPRECATED); |
63 } | 63 } |
64 | 64 |
65 if ($constraint->multiple) { | 65 if ($constraint->multiple) { |
66 foreach ($value as $_value) { | 66 foreach ($value as $_value) { |
67 if (!in_array($_value, $choices, $constraint->strict)) { | 67 if (!\in_array($_value, $choices, $constraint->strict)) { |
68 $this->context->buildViolation($constraint->multipleMessage) | 68 $this->context->buildViolation($constraint->multipleMessage) |
69 ->setParameter('{{ value }}', $this->formatValue($_value)) | 69 ->setParameter('{{ value }}', $this->formatValue($_value)) |
70 ->setCode(Choice::NO_SUCH_CHOICE_ERROR) | 70 ->setCode(Choice::NO_SUCH_CHOICE_ERROR) |
71 ->setInvalidValue($_value) | 71 ->setInvalidValue($_value) |
72 ->addViolation(); | 72 ->addViolation(); |
73 | 73 |
74 return; | 74 return; |
75 } | 75 } |
76 } | 76 } |
77 | 77 |
78 $count = count($value); | 78 $count = \count($value); |
79 | 79 |
80 if (null !== $constraint->min && $count < $constraint->min) { | 80 if (null !== $constraint->min && $count < $constraint->min) { |
81 $this->context->buildViolation($constraint->minMessage) | 81 $this->context->buildViolation($constraint->minMessage) |
82 ->setParameter('{{ limit }}', $constraint->min) | 82 ->setParameter('{{ limit }}', $constraint->min) |
83 ->setPlural((int) $constraint->min) | 83 ->setPlural((int) $constraint->min) |
94 ->setCode(Choice::TOO_MANY_ERROR) | 94 ->setCode(Choice::TOO_MANY_ERROR) |
95 ->addViolation(); | 95 ->addViolation(); |
96 | 96 |
97 return; | 97 return; |
98 } | 98 } |
99 } elseif (!in_array($value, $choices, $constraint->strict)) { | 99 } elseif (!\in_array($value, $choices, $constraint->strict)) { |
100 $this->context->buildViolation($constraint->message) | 100 $this->context->buildViolation($constraint->message) |
101 ->setParameter('{{ value }}', $this->formatValue($value)) | 101 ->setParameter('{{ value }}', $this->formatValue($value)) |
102 ->setCode(Choice::NO_SUCH_CHOICE_ERROR) | 102 ->setCode(Choice::NO_SUCH_CHOICE_ERROR) |
103 ->addViolation(); | 103 ->addViolation(); |
104 } | 104 } |