Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 160 lines (139 sloc) 3.245 kb
c56d28d @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
1 <?php
2
06fcab5 @fabpot [Validation] fixed license
fabpot authored
3 /*
64e1cf2 @blue-eyes normalized license messages in PHP files
blue-eyes authored
4 * This file is part of the Symfony package.
06fcab5 @fabpot [Validation] fixed license
fabpot authored
5 *
fec10a4 @fabpot replaced symfony-project.org by symfony.com
fabpot authored
6 * (c) Fabien Potencier <fabien@symfony.com>
06fcab5 @fabpot [Validation] fixed license
fabpot authored
7 *
64e1cf2 @blue-eyes normalized license messages in PHP files
blue-eyes authored
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
06fcab5 @fabpot [Validation] fixed license
fabpot authored
10 */
11
64e1cf2 @blue-eyes normalized license messages in PHP files
blue-eyes authored
12 namespace Symfony\Component\Validator;
13
b309adc @weaverryan [Validator] Adding a significant amount of PHPDoc to the Validator co…
weaverryan authored
14 /**
a7a50fc @webmozart [Validator] Refactored the GraphWalker into an implementation of the …
webmozart authored
15 * Default implementation of {@ConstraintViolationListInterface}.
1dcf190 @webmozart [Validator] Fixed: GraphWalker does not add constraint violation if e…
webmozart authored
16 *
17 * @author Bernhard Schussek <bschussek@gmail.com>
b309adc @weaverryan [Validator] Adding a significant amount of PHPDoc to the Validator co…
weaverryan authored
18 */
a7a50fc @webmozart [Validator] Refactored the GraphWalker into an implementation of the …
webmozart authored
19 class ConstraintViolationList implements \IteratorAggregate, ConstraintViolationListInterface
c56d28d @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
20 {
1dcf190 @webmozart [Validator] Fixed: GraphWalker does not add constraint violation if e…
webmozart authored
21 /**
a7a50fc @webmozart [Validator] Refactored the GraphWalker into an implementation of the …
webmozart authored
22 * @var ConstraintViolationInterface[]
1dcf190 @webmozart [Validator] Fixed: GraphWalker does not add constraint violation if e…
webmozart authored
23 */
a7a50fc @webmozart [Validator] Refactored the GraphWalker into an implementation of the …
webmozart authored
24 private $violations = array();
c56d28d @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
25
b309adc @weaverryan [Validator] Adding a significant amount of PHPDoc to the Validator co…
weaverryan authored
26 /**
626964f @webmozart [Form] Fixed typos
webmozart authored
27 * Creates a new constraint violation list.
1dcf190 @webmozart [Validator] Fixed: GraphWalker does not add constraint violation if e…
webmozart authored
28 *
a7a50fc @webmozart [Validator] Refactored the GraphWalker into an implementation of the …
webmozart authored
29 * @param ConstraintViolationInterface[] $violations The constraint violations to add to the list
1dcf190 @webmozart [Validator] Fixed: GraphWalker does not add constraint violation if e…
webmozart authored
30 */
31 public function __construct(array $violations = array())
32 {
33 foreach ($violations as $violation) {
34 $this->add($violation);
35 }
36 }
37
38 /**
a7a50fc @webmozart [Validator] Refactored the GraphWalker into an implementation of the …
webmozart authored
39 * Converts the violation into a string for debugging purposes.
40 *
41 * @return string The violation as string.
b309adc @weaverryan [Validator] Adding a significant amount of PHPDoc to the Validator co…
weaverryan authored
42 */
c56d28d @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
43 public function __toString()
44 {
45 $string = '';
46
47 foreach ($this->violations as $violation) {
4667a46 @canni [CS Fix] Consistent coding-style of concatenation operator usage
canni authored
48 $string .= $violation."\n";
c56d28d @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
49 }
50
51 return $string;
52 }
53
b309adc @weaverryan [Validator] Adding a significant amount of PHPDoc to the Validator co…
weaverryan authored
54 /**
1311387 @fabpot made {@inheritdoc} annotations consistent across the board
fabpot authored
55 * {@inheritdoc}
b309adc @weaverryan [Validator] Adding a significant amount of PHPDoc to the Validator co…
weaverryan authored
56 */
a7a50fc @webmozart [Validator] Refactored the GraphWalker into an implementation of the …
webmozart authored
57 public function add(ConstraintViolationInterface $violation)
c56d28d @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
58 {
59 $this->violations[] = $violation;
60 }
61
b309adc @weaverryan [Validator] Adding a significant amount of PHPDoc to the Validator co…
weaverryan authored
62 /**
1311387 @fabpot made {@inheritdoc} annotations consistent across the board
fabpot authored
63 * {@inheritdoc}
b309adc @weaverryan [Validator] Adding a significant amount of PHPDoc to the Validator co…
weaverryan authored
64 */
a7a50fc @webmozart [Validator] Refactored the GraphWalker into an implementation of the …
webmozart authored
65 public function addAll(ConstraintViolationListInterface $otherList)
c56d28d @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
66 {
a7a50fc @webmozart [Validator] Refactored the GraphWalker into an implementation of the …
webmozart authored
67 foreach ($otherList as $violation) {
c56d28d @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
68 $this->violations[] = $violation;
69 }
70 }
71
b309adc @weaverryan [Validator] Adding a significant amount of PHPDoc to the Validator co…
weaverryan authored
72 /**
1311387 @fabpot made {@inheritdoc} annotations consistent across the board
fabpot authored
73 * {@inheritdoc}
02e02b7 @webmozart [Form] Allowed native framework errors to be mapped as well
webmozart authored
74 */
75 public function get($offset)
76 {
77 if (!isset($this->violations[$offset])) {
78 throw new \OutOfBoundsException(sprintf('The offset "%s" does not exist.', $offset));
79 }
80
81 return $this->violations[$offset];
82 }
83
84 /**
1311387 @fabpot made {@inheritdoc} annotations consistent across the board
fabpot authored
85 * {@inheritdoc}
02e02b7 @webmozart [Form] Allowed native framework errors to be mapped as well
webmozart authored
86 */
87 public function has($offset)
88 {
89 return isset($this->violations[$offset]);
90 }
91
92 /**
1311387 @fabpot made {@inheritdoc} annotations consistent across the board
fabpot authored
93 * {@inheritdoc}
02e02b7 @webmozart [Form] Allowed native framework errors to be mapped as well
webmozart authored
94 */
a7a50fc @webmozart [Validator] Refactored the GraphWalker into an implementation of the …
webmozart authored
95 public function set($offset, ConstraintViolationInterface $violation)
02e02b7 @webmozart [Form] Allowed native framework errors to be mapped as well
webmozart authored
96 {
97 $this->violations[$offset] = $violation;
98 }
99
100 /**
1311387 @fabpot made {@inheritdoc} annotations consistent across the board
fabpot authored
101 * {@inheritdoc}
02e02b7 @webmozart [Form] Allowed native framework errors to be mapped as well
webmozart authored
102 */
103 public function remove($offset)
104 {
105 unset($this->violations[$offset]);
106 }
107
108 /**
1311387 @fabpot made {@inheritdoc} annotations consistent across the board
fabpot authored
109 * {@inheritdoc}
b309adc @weaverryan [Validator] Adding a significant amount of PHPDoc to the Validator co…
weaverryan authored
110 */
c56d28d @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
111 public function getIterator()
112 {
113 return new \ArrayIterator($this->violations);
114 }
115
b309adc @weaverryan [Validator] Adding a significant amount of PHPDoc to the Validator co…
weaverryan authored
116 /**
1311387 @fabpot made {@inheritdoc} annotations consistent across the board
fabpot authored
117 * {@inheritdoc}
b309adc @weaverryan [Validator] Adding a significant amount of PHPDoc to the Validator co…
weaverryan authored
118 */
c56d28d @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
119 public function count()
120 {
121 return count($this->violations);
122 }
c210ba1 Implemented ArrayAccess interface
Mark Challoner authored
123
124 /**
1311387 @fabpot made {@inheritdoc} annotations consistent across the board
fabpot authored
125 * {@inheritdoc}
c210ba1 Implemented ArrayAccess interface
Mark Challoner authored
126 */
127 public function offsetExists($offset)
128 {
02e02b7 @webmozart [Form] Allowed native framework errors to be mapped as well
webmozart authored
129 return $this->has($offset);
c210ba1 Implemented ArrayAccess interface
Mark Challoner authored
130 }
131
132 /**
1311387 @fabpot made {@inheritdoc} annotations consistent across the board
fabpot authored
133 * {@inheritdoc}
c210ba1 Implemented ArrayAccess interface
Mark Challoner authored
134 */
135 public function offsetGet($offset)
136 {
02e02b7 @webmozart [Form] Allowed native framework errors to be mapped as well
webmozart authored
137 return $this->get($offset);
c210ba1 Implemented ArrayAccess interface
Mark Challoner authored
138 }
139
140 /**
1311387 @fabpot made {@inheritdoc} annotations consistent across the board
fabpot authored
141 * {@inheritdoc}
c210ba1 Implemented ArrayAccess interface
Mark Challoner authored
142 */
02e02b7 @webmozart [Form] Allowed native framework errors to be mapped as well
webmozart authored
143 public function offsetSet($offset, $violation)
c210ba1 Implemented ArrayAccess interface
Mark Challoner authored
144 {
859d266 [Validator] Updated ContraintViolationList ArrayAccess setter to chec…
Mark Challoner authored
145 if (null === $offset) {
02e02b7 @webmozart [Form] Allowed native framework errors to be mapped as well
webmozart authored
146 $this->add($violation);
c210ba1 Implemented ArrayAccess interface
Mark Challoner authored
147 } else {
02e02b7 @webmozart [Form] Allowed native framework errors to be mapped as well
webmozart authored
148 $this->set($offset, $violation);
c210ba1 Implemented ArrayAccess interface
Mark Challoner authored
149 }
150 }
151
152 /**
1311387 @fabpot made {@inheritdoc} annotations consistent across the board
fabpot authored
153 * {@inheritdoc}
c210ba1 Implemented ArrayAccess interface
Mark Challoner authored
154 */
155 public function offsetUnset($offset)
156 {
02e02b7 @webmozart [Form] Allowed native framework errors to be mapped as well
webmozart authored
157 $this->remove($offset);
c210ba1 Implemented ArrayAccess interface
Mark Challoner authored
158 }
2d8d332 @fabpot fixed CS
fabpot authored
159 }
Something went wrong with that request. Please try again.