PageRenderTime 54ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/symfony/symfony/src/Symfony/Component/Validator/Constraints/GroupSequence.php

https://gitlab.com/matijabelec/bigpandadev
PHP | 213 lines | 52 code | 21 blank | 140 comment | 2 complexity | bf1805b2173b0059fc60a62e044d0ed2 MD5 | raw file
  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\Exception\OutOfBoundsException;
  12. /**
  13. * A sequence of validation groups.
  14. *
  15. * When validating a group sequence, each group will only be validated if all
  16. * of the previous groups in the sequence succeeded. For example:
  17. *
  18. * $validator->validate($address, null, new GroupSequence('Basic', 'Strict'));
  19. *
  20. * In the first step, all constraints that belong to the group "Basic" will be
  21. * validated. If none of the constraints fail, the validator will then validate
  22. * the constraints in group "Strict". This is useful, for example, if "Strict"
  23. * contains expensive checks that require a lot of CPU or slow, external
  24. * services. You usually don't want to run expensive checks if any of the cheap
  25. * checks fail.
  26. *
  27. * When adding metadata to a class, you can override the "Default" group of
  28. * that class with a group sequence:
  29. *
  30. * /**
  31. * * @GroupSequence({"Address", "Strict"})
  32. * *\/
  33. * class Address
  34. * {
  35. * // ...
  36. * }
  37. *
  38. * Whenever you validate that object in the "Default" group, the group sequence
  39. * will be validated:
  40. *
  41. * $validator->validate($address);
  42. *
  43. * If you want to execute the constraints of the "Default" group for a class
  44. * with an overridden default group, pass the class name as group name instead:
  45. *
  46. * $validator->validate($address, null, "Address")
  47. *
  48. * @Annotation
  49. * @Target({"CLASS", "ANNOTATION"})
  50. *
  51. * @author Bernhard Schussek <bschussek@gmail.com>
  52. *
  53. * @api
  54. *
  55. * Implementing \ArrayAccess, \IteratorAggregate and \Countable is @deprecated since 2.5 and will be removed in 3.0.
  56. */
  57. class GroupSequence implements \ArrayAccess, \IteratorAggregate, \Countable
  58. {
  59. /**
  60. * The groups in the sequence.
  61. *
  62. * @var string[]|GroupSequence[]
  63. */
  64. public $groups;
  65. /**
  66. * The group in which cascaded objects are validated when validating
  67. * this sequence.
  68. *
  69. * By default, cascaded objects are validated in each of the groups of
  70. * the sequence.
  71. *
  72. * If a class has a group sequence attached, that sequence replaces the
  73. * "Default" group. When validating that class in the "Default" group, the
  74. * group sequence is used instead, but still the "Default" group should be
  75. * cascaded to other objects.
  76. *
  77. * @var string|GroupSequence
  78. */
  79. public $cascadedGroup;
  80. /**
  81. * Creates a new group sequence.
  82. *
  83. * @param string[] $groups The groups in the sequence
  84. */
  85. public function __construct(array $groups)
  86. {
  87. // Support for Doctrine annotations
  88. $this->groups = isset($groups['value']) ? $groups['value'] : $groups;
  89. }
  90. /**
  91. * Returns an iterator for this group.
  92. *
  93. * Implemented for backwards compatibility with Symfony < 2.5.
  94. *
  95. * @return \Traversable The iterator
  96. *
  97. * @see \IteratorAggregate::getIterator()
  98. * @deprecated since version 2.5, to be removed in 3.0.
  99. */
  100. public function getIterator()
  101. {
  102. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
  103. return new \ArrayIterator($this->groups);
  104. }
  105. /**
  106. * Returns whether the given offset exists in the sequence.
  107. *
  108. * Implemented for backwards compatibility with Symfony < 2.5.
  109. *
  110. * @param int $offset The offset
  111. *
  112. * @return bool Whether the offset exists
  113. *
  114. * @deprecated since version 2.5, to be removed in 3.0.
  115. */
  116. public function offsetExists($offset)
  117. {
  118. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
  119. return isset($this->groups[$offset]);
  120. }
  121. /**
  122. * Returns the group at the given offset.
  123. *
  124. * Implemented for backwards compatibility with Symfony < 2.5.
  125. *
  126. * @param int $offset The offset
  127. *
  128. * @return string The group a the given offset
  129. *
  130. * @throws OutOfBoundsException If the object does not exist
  131. *
  132. * @deprecated since version 2.5, to be removed in 3.0.
  133. */
  134. public function offsetGet($offset)
  135. {
  136. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
  137. if (!isset($this->groups[$offset])) {
  138. throw new OutOfBoundsException(sprintf(
  139. 'The offset "%s" does not exist.',
  140. $offset
  141. ));
  142. }
  143. return $this->groups[$offset];
  144. }
  145. /**
  146. * Sets the group at the given offset.
  147. *
  148. * Implemented for backwards compatibility with Symfony < 2.5.
  149. *
  150. * @param int $offset The offset
  151. * @param string $value The group name
  152. *
  153. * @deprecated since version 2.5, to be removed in 3.0.
  154. */
  155. public function offsetSet($offset, $value)
  156. {
  157. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
  158. if (null !== $offset) {
  159. $this->groups[$offset] = $value;
  160. return;
  161. }
  162. $this->groups[] = $value;
  163. }
  164. /**
  165. * Removes the group at the given offset.
  166. *
  167. * Implemented for backwards compatibility with Symfony < 2.5.
  168. *
  169. * @param int $offset The offset
  170. *
  171. * @deprecated since version 2.5, to be removed in 3.0.
  172. */
  173. public function offsetUnset($offset)
  174. {
  175. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
  176. unset($this->groups[$offset]);
  177. }
  178. /**
  179. * Returns the number of groups in the sequence.
  180. *
  181. * Implemented for backwards compatibility with Symfony < 2.5.
  182. *
  183. * @return int The number of groups
  184. *
  185. * @deprecated since version 2.5, to be removed in 3.0.
  186. */
  187. public function count()
  188. {
  189. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
  190. return count($this->groups);
  191. }
  192. }