| @@ 7-55 (lines=49) @@ | ||
| 4 | ||
| 5 | use Symfony\Component\Validator\Constraint; |
|
| 6 | ||
| 7 | trait ConstraintsTrait |
|
| 8 | { |
|
| 9 | use OptionAccessorsTrait; |
|
| 10 | ||
| 11 | /** |
|
| 12 | * @param array $constraints |
|
| 13 | * @return $this |
|
| 14 | * @link http://symfony.com/doc/current/reference/forms/types/form.html#constraints |
|
| 15 | */ |
|
| 16 | public function setConstraints(array $constraints) |
|
| 17 | { |
|
| 18 | return $this->setOption('constraints', $constraints); |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @param Constraint $constraint |
|
| 23 | * @return $this |
|
| 24 | * @link http://symfony.com/doc/current/reference/forms/types/form.html#constraints |
|
| 25 | */ |
|
| 26 | public function addConstraint(Constraint $constraint) |
|
| 27 | { |
|
| 28 | $constraints = $this->getConstraints(); |
|
| 29 | if (is_array($constraints) === false) { |
|
| 30 | $constraints = array(); |
|
| 31 | } |
|
| 32 | $constraints[] = $constraint; |
|
| 33 | $this->setConstraints($constraints); |
|
| 34 | ||
| 35 | return $this; |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * @return array|string |
|
| 40 | * @link http://symfony.com/doc/current/reference/forms/types/form.html#constraints |
|
| 41 | */ |
|
| 42 | public function getConstraints() |
|
| 43 | { |
|
| 44 | return $this->getOption('constraints'); |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * @return $this |
|
| 49 | * @link http://symfony.com/doc/current/reference/forms/types/form.html#constraints |
|
| 50 | */ |
|
| 51 | public function removeConstraints() |
|
| 52 | { |
|
| 53 | return $this->removeOption('constraints'); |
|
| 54 | } |
|
| 55 | } |
|
| 56 | ||
| @@ 5-59 (lines=55) @@ | ||
| 2 | ||
| 3 | namespace steevanb\SymfonyFormOptionsBuilder\Behavior; |
|
| 4 | ||
| 5 | trait ValidationGroupsTrait |
|
| 6 | { |
|
| 7 | use OptionAccessorsTrait; |
|
| 8 | ||
| 9 | /** |
|
| 10 | * @param null|false|array|\Closure $groups |
|
| 11 | * @return $this |
|
| 12 | * @link http://symfony.com/doc/current/reference/forms/types/submit.html#validation-groups |
|
| 13 | */ |
|
| 14 | public function setValidationGroups($groups) |
|
| 15 | { |
|
| 16 | return $this->setOption('validation_groups', $groups); |
|
| 17 | } |
|
| 18 | ||
| 19 | /** |
|
| 20 | * @param null|false|array|\Closure $group |
|
| 21 | * @return $this |
|
| 22 | */ |
|
| 23 | public function addValidationGroup($group) |
|
| 24 | { |
|
| 25 | $groups = $this->getValidationGroups(); |
|
| 26 | if (in_array($group, $groups) === false) { |
|
| 27 | $groups[] = $group; |
|
| 28 | } |
|
| 29 | ||
| 30 | return $this->setValidationGroups($groups); |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * @param string $group |
|
| 35 | * @return bool |
|
| 36 | * @link http://symfony.com/doc/current/reference/forms/types/submit.html#validation-groups |
|
| 37 | */ |
|
| 38 | public function hasValidationGroup($group) |
|
| 39 | { |
|
| 40 | return in_array($group, $this->getValidationGroups()); |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @return null|false|array|\Closure |
|
| 45 | * @link http://symfony.com/doc/current/reference/forms/types/submit.html#validation-groups |
|
| 46 | */ |
|
| 47 | public function getValidationGroups() |
|
| 48 | { |
|
| 49 | return $this->getOption('validation_groups'); |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * @return $this |
|
| 54 | */ |
|
| 55 | public function removeValidationGroups() |
|
| 56 | { |
|
| 57 | return $this->removeOption('validation_groups'); |
|
| 58 | } |
|
| 59 | } |
|
| 60 | ||