diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-04 17:50:34 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-04 17:50:34 +0200 |
commit | 46b77928f746a4231d064774b5b67fd892c7ce86 (patch) | |
tree | e3ea690b3f0def1744ddae758923cf92171ef985 /vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper | |
parent | 68abd9c71b1d2f7bb2e9d21819584d1d15005b25 (diff) | |
download | wallabag-46b77928f746a4231d064774b5b67fd892c7ce86.tar.gz wallabag-46b77928f746a4231d064774b5b67fd892c7ce86.tar.zst wallabag-46b77928f746a4231d064774b5b67fd892c7ce86.zip |
rm vendor
Diffstat (limited to 'vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper')
6 files changed, 0 insertions, 763 deletions
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/MappingRule.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/MappingRule.php deleted file mode 100644 index 7b96efb4..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/MappingRule.php +++ /dev/null | |||
@@ -1,106 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Validator\ViolationMapper; | ||
13 | |||
14 | use Symfony\Component\Form\FormInterface; | ||
15 | use Symfony\Component\Form\Exception\ErrorMappingException; | ||
16 | |||
17 | /** | ||
18 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
19 | */ | ||
20 | class MappingRule | ||
21 | { | ||
22 | /** | ||
23 | * @var FormInterface | ||
24 | */ | ||
25 | private $origin; | ||
26 | |||
27 | /** | ||
28 | * @var string | ||
29 | */ | ||
30 | private $propertyPath; | ||
31 | |||
32 | /** | ||
33 | * @var string | ||
34 | */ | ||
35 | private $targetPath; | ||
36 | |||
37 | public function __construct(FormInterface $origin, $propertyPath, $targetPath) | ||
38 | { | ||
39 | $this->origin = $origin; | ||
40 | $this->propertyPath = $propertyPath; | ||
41 | $this->targetPath = $targetPath; | ||
42 | } | ||
43 | |||
44 | /** | ||
45 | * @return FormInterface | ||
46 | */ | ||
47 | public function getOrigin() | ||
48 | { | ||
49 | return $this->origin; | ||
50 | } | ||
51 | |||
52 | /** | ||
53 | * Matches a property path against the rule path. | ||
54 | * | ||
55 | * If the rule matches, the form mapped by the rule is returned. | ||
56 | * Otherwise this method returns false. | ||
57 | * | ||
58 | * @param string $propertyPath The property path to match against the rule. | ||
59 | * | ||
60 | * @return null|FormInterface The mapped form or null. | ||
61 | */ | ||
62 | public function match($propertyPath) | ||
63 | { | ||
64 | if ($propertyPath === (string) $this->propertyPath) { | ||
65 | return $this->getTarget(); | ||
66 | } | ||
67 | |||
68 | return null; | ||
69 | } | ||
70 | |||
71 | /** | ||
72 | * Matches a property path against a prefix of the rule path. | ||
73 | * | ||
74 | * @param string $propertyPath The property path to match against the rule. | ||
75 | * | ||
76 | * @return Boolean Whether the property path is a prefix of the rule or not. | ||
77 | */ | ||
78 | public function isPrefix($propertyPath) | ||
79 | { | ||
80 | $length = strlen($propertyPath); | ||
81 | $prefix = substr($this->propertyPath, 0, $length); | ||
82 | $next = isset($this->propertyPath[$length]) ? $this->propertyPath[$length] : null; | ||
83 | |||
84 | return $prefix === $propertyPath && ('[' === $next || '.' === $next); | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * @return FormInterface | ||
89 | * | ||
90 | * @throws ErrorMappingException | ||
91 | */ | ||
92 | public function getTarget() | ||
93 | { | ||
94 | $childNames = explode('.', $this->targetPath); | ||
95 | $target = $this->origin; | ||
96 | |||
97 | foreach ($childNames as $childName) { | ||
98 | if (!$target->has($childName)) { | ||
99 | throw new ErrorMappingException(sprintf('The child "%s" of "%s" mapped by the rule "%s" in "%s" does not exist.', $childName, $target->getName(), $this->targetPath, $this->origin->getName())); | ||
100 | } | ||
101 | $target = $target->get($childName); | ||
102 | } | ||
103 | |||
104 | return $target; | ||
105 | } | ||
106 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/RelativePath.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/RelativePath.php deleted file mode 100644 index ef5c9fad..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/RelativePath.php +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Validator\ViolationMapper; | ||
13 | |||
14 | use Symfony\Component\Form\FormInterface; | ||
15 | use Symfony\Component\PropertyAccess\PropertyPath; | ||
16 | |||
17 | /** | ||
18 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
19 | */ | ||
20 | class RelativePath extends PropertyPath | ||
21 | { | ||
22 | /** | ||
23 | * @var FormInterface | ||
24 | */ | ||
25 | private $root; | ||
26 | |||
27 | /** | ||
28 | * @param FormInterface $root | ||
29 | * @param string $propertyPath | ||
30 | */ | ||
31 | public function __construct(FormInterface $root, $propertyPath) | ||
32 | { | ||
33 | parent::__construct($propertyPath); | ||
34 | |||
35 | $this->root = $root; | ||
36 | } | ||
37 | |||
38 | /** | ||
39 | * @return FormInterface | ||
40 | */ | ||
41 | public function getRoot() | ||
42 | { | ||
43 | return $this->root; | ||
44 | } | ||
45 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php deleted file mode 100644 index 8a7636c7..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php +++ /dev/null | |||
@@ -1,299 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Validator\ViolationMapper; | ||
13 | |||
14 | use Symfony\Component\Form\FormInterface; | ||
15 | use Symfony\Component\Form\Util\InheritDataAwareIterator; | ||
16 | use Symfony\Component\PropertyAccess\PropertyPathIterator; | ||
17 | use Symfony\Component\PropertyAccess\PropertyPathBuilder; | ||
18 | use Symfony\Component\PropertyAccess\PropertyPathIteratorInterface; | ||
19 | use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationPathIterator; | ||
20 | use Symfony\Component\Form\FormError; | ||
21 | use Symfony\Component\Validator\ConstraintViolation; | ||
22 | |||
23 | /** | ||
24 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
25 | */ | ||
26 | class ViolationMapper implements ViolationMapperInterface | ||
27 | { | ||
28 | /** | ||
29 | * @var Boolean | ||
30 | */ | ||
31 | private $allowNonSynchronized; | ||
32 | |||
33 | /** | ||
34 | * {@inheritdoc} | ||
35 | */ | ||
36 | public function mapViolation(ConstraintViolation $violation, FormInterface $form, $allowNonSynchronized = false) | ||
37 | { | ||
38 | $this->allowNonSynchronized = $allowNonSynchronized; | ||
39 | |||
40 | // The scope is the currently found most specific form that | ||
41 | // an error should be mapped to. After setting the scope, the | ||
42 | // mapper will try to continue to find more specific matches in | ||
43 | // the children of scope. If it cannot, the error will be | ||
44 | // mapped to this scope. | ||
45 | $scope = null; | ||
46 | |||
47 | $violationPath = null; | ||
48 | $relativePath = null; | ||
49 | $match = false; | ||
50 | |||
51 | // Don't create a ViolationPath instance for empty property paths | ||
52 | if (strlen($violation->getPropertyPath()) > 0) { | ||
53 | $violationPath = new ViolationPath($violation->getPropertyPath()); | ||
54 | $relativePath = $this->reconstructPath($violationPath, $form); | ||
55 | } | ||
56 | |||
57 | // This case happens if the violation path is empty and thus | ||
58 | // the violation should be mapped to the root form | ||
59 | if (null === $violationPath) { | ||
60 | $scope = $form; | ||
61 | } | ||
62 | |||
63 | // In general, mapping happens from the root form to the leaf forms | ||
64 | // First, the rules of the root form are applied to determine | ||
65 | // the subsequent descendant. The rules of this descendant are then | ||
66 | // applied to find the next and so on, until we have found the | ||
67 | // most specific form that matches the violation. | ||
68 | |||
69 | // If any of the forms found in this process is not synchronized, | ||
70 | // mapping is aborted. Non-synchronized forms could not reverse | ||
71 | // transform the value entered by the user, thus any further violations | ||
72 | // caused by the (invalid) reverse transformed value should be | ||
73 | // ignored. | ||
74 | |||
75 | if (null !== $relativePath) { | ||
76 | // Set the scope to the root of the relative path | ||
77 | // This root will usually be $form. If the path contains | ||
78 | // an unmapped form though, the last unmapped form found | ||
79 | // will be the root of the path. | ||
80 | $scope = $relativePath->getRoot(); | ||
81 | $it = new PropertyPathIterator($relativePath); | ||
82 | |||
83 | while ($this->acceptsErrors($scope) && null !== ($child = $this->matchChild($scope, $it))) { | ||
84 | $scope = $child; | ||
85 | $it->next(); | ||
86 | $match = true; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | // This case happens if an error happened in the data under a | ||
91 | // form inheriting its parent data that does not match any of the | ||
92 | // children of that form. | ||
93 | if (null !== $violationPath && !$match) { | ||
94 | // If we could not map the error to anything more specific | ||
95 | // than the root element, map it to the innermost directly | ||
96 | // mapped form of the violation path | ||
97 | // e.g. "children[foo].children[bar].data.baz" | ||
98 | // Here the innermost directly mapped child is "bar" | ||
99 | |||
100 | $scope = $form; | ||
101 | $it = new ViolationPathIterator($violationPath); | ||
102 | |||
103 | // Note: acceptsErrors() will always return true for forms inheriting | ||
104 | // their parent data, because these forms can never be non-synchronized | ||
105 | // (they don't do any data transformation on their own) | ||
106 | while ($this->acceptsErrors($scope) && $it->valid() && $it->mapsForm()) { | ||
107 | if (!$scope->has($it->current())) { | ||
108 | // Break if we find a reference to a non-existing child | ||
109 | break; | ||
110 | } | ||
111 | |||
112 | $scope = $scope->get($it->current()); | ||
113 | $it->next(); | ||
114 | } | ||
115 | } | ||
116 | |||
117 | // Follow dot rules until we have the final target | ||
118 | $mapping = $scope->getConfig()->getOption('error_mapping'); | ||
119 | |||
120 | while ($this->acceptsErrors($scope) && isset($mapping['.'])) { | ||
121 | $dotRule = new MappingRule($scope, '.', $mapping['.']); | ||
122 | $scope = $dotRule->getTarget(); | ||
123 | $mapping = $scope->getConfig()->getOption('error_mapping'); | ||
124 | } | ||
125 | |||
126 | // Only add the error if the form is synchronized | ||
127 | if ($this->acceptsErrors($scope)) { | ||
128 | $scope->addError(new FormError( | ||
129 | $violation->getMessage(), | ||
130 | $violation->getMessageTemplate(), | ||
131 | $violation->getMessageParameters(), | ||
132 | $violation->getMessagePluralization() | ||
133 | )); | ||
134 | } | ||
135 | } | ||
136 | |||
137 | /** | ||
138 | * Tries to match the beginning of the property path at the | ||
139 | * current position against the children of the scope. | ||
140 | * | ||
141 | * If a matching child is found, it is returned. Otherwise | ||
142 | * null is returned. | ||
143 | * | ||
144 | * @param FormInterface $form The form to search. | ||
145 | * @param PropertyPathIteratorInterface $it The iterator at its current position. | ||
146 | * | ||
147 | * @return null|FormInterface The found match or null. | ||
148 | */ | ||
149 | private function matchChild(FormInterface $form, PropertyPathIteratorInterface $it) | ||
150 | { | ||
151 | // Remember at what property path underneath "data" | ||
152 | // we are looking. Check if there is a child with that | ||
153 | // path, otherwise increase path by one more piece | ||
154 | $chunk = ''; | ||
155 | $foundChild = null; | ||
156 | $foundAtIndex = 0; | ||
157 | |||
158 | // Construct mapping rules for the given form | ||
159 | $rules = array(); | ||
160 | |||
161 | foreach ($form->getConfig()->getOption('error_mapping') as $propertyPath => $targetPath) { | ||
162 | // Dot rules are considered at the very end | ||
163 | if ('.' !== $propertyPath) { | ||
164 | $rules[] = new MappingRule($form, $propertyPath, $targetPath); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | // Skip forms inheriting their parent data when iterating the children | ||
169 | $childIterator = new \RecursiveIteratorIterator( | ||
170 | new InheritDataAwareIterator($form->all()) | ||
171 | ); | ||
172 | |||
173 | // Make the path longer until we find a matching child | ||
174 | while (true) { | ||
175 | if (!$it->valid()) { | ||
176 | return null; | ||
177 | } | ||
178 | |||
179 | if ($it->isIndex()) { | ||
180 | $chunk .= '['.$it->current().']'; | ||
181 | } else { | ||
182 | $chunk .= ('' === $chunk ? '' : '.').$it->current(); | ||
183 | } | ||
184 | |||
185 | // Test mapping rules as long as we have any | ||
186 | foreach ($rules as $key => $rule) { | ||
187 | /* @var MappingRule $rule */ | ||
188 | |||
189 | // Mapping rule matches completely, terminate. | ||
190 | if (null !== ($form = $rule->match($chunk))) { | ||
191 | return $form; | ||
192 | } | ||
193 | |||
194 | // Keep only rules that have $chunk as prefix | ||
195 | if (!$rule->isPrefix($chunk)) { | ||
196 | unset($rules[$key]); | ||
197 | } | ||
198 | } | ||
199 | |||
200 | // Test children unless we already found one | ||
201 | if (null === $foundChild) { | ||
202 | foreach ($childIterator as $child) { | ||
203 | /* @var FormInterface $child */ | ||
204 | $childPath = (string) $child->getPropertyPath(); | ||
205 | |||
206 | // Child found, mark as return value | ||
207 | if ($chunk === $childPath) { | ||
208 | $foundChild = $child; | ||
209 | $foundAtIndex = $it->key(); | ||
210 | } | ||
211 | } | ||
212 | } | ||
213 | |||
214 | // Add element to the chunk | ||
215 | $it->next(); | ||
216 | |||
217 | // If we reached the end of the path or if there are no | ||
218 | // more matching mapping rules, return the found child | ||
219 | if (null !== $foundChild && (!$it->valid() || count($rules) === 0)) { | ||
220 | // Reset index in case we tried to find mapping | ||
221 | // rules further down the path | ||
222 | $it->seek($foundAtIndex); | ||
223 | |||
224 | return $foundChild; | ||
225 | } | ||
226 | } | ||
227 | |||
228 | return null; | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * Reconstructs a property path from a violation path and a form tree. | ||
233 | * | ||
234 | * @param ViolationPath $violationPath The violation path. | ||
235 | * @param FormInterface $origin The root form of the tree. | ||
236 | * | ||
237 | * @return RelativePath The reconstructed path. | ||
238 | */ | ||
239 | private function reconstructPath(ViolationPath $violationPath, FormInterface $origin) | ||
240 | { | ||
241 | $propertyPathBuilder = new PropertyPathBuilder($violationPath); | ||
242 | $it = $violationPath->getIterator(); | ||
243 | $scope = $origin; | ||
244 | |||
245 | // Remember the current index in the builder | ||
246 | $i = 0; | ||
247 | |||
248 | // Expand elements that map to a form (like "children[address]") | ||
249 | for ($it->rewind(); $it->valid() && $it->mapsForm(); $it->next()) { | ||
250 | if (!$scope->has($it->current())) { | ||
251 | // Scope relates to a form that does not exist | ||
252 | // Bail out | ||
253 | break; | ||
254 | } | ||
255 | |||
256 | // Process child form | ||
257 | $scope = $scope->get($it->current()); | ||
258 | |||
259 | if ($scope->getConfig()->getInheritData()) { | ||
260 | // Form inherits its parent data | ||
261 | // Cut the piece out of the property path and proceed | ||
262 | $propertyPathBuilder->remove($i); | ||
263 | } elseif (!$scope->getConfig()->getMapped()) { | ||
264 | // Form is not mapped | ||
265 | // Set the form as new origin and strip everything | ||
266 | // we have so far in the path | ||
267 | $origin = $scope; | ||
268 | $propertyPathBuilder->remove(0, $i + 1); | ||
269 | $i = 0; | ||
270 | } else { | ||
271 | /* @var \Symfony\Component\PropertyAccess\PropertyPathInterface $propertyPath */ | ||
272 | $propertyPath = $scope->getPropertyPath(); | ||
273 | |||
274 | if (null === $propertyPath) { | ||
275 | // Property path of a mapped form is null | ||
276 | // Should not happen, bail out | ||
277 | break; | ||
278 | } | ||
279 | |||
280 | $propertyPathBuilder->replace($i, 1, $propertyPath); | ||
281 | $i += $propertyPath->getLength(); | ||
282 | } | ||
283 | } | ||
284 | |||
285 | $finalPath = $propertyPathBuilder->getPropertyPath(); | ||
286 | |||
287 | return null !== $finalPath ? new RelativePath($origin, $finalPath) : null; | ||
288 | } | ||
289 | |||
290 | /** | ||
291 | * @param FormInterface $form | ||
292 | * | ||
293 | * @return Boolean | ||
294 | */ | ||
295 | private function acceptsErrors(FormInterface $form) | ||
296 | { | ||
297 | return $this->allowNonSynchronized || $form->isSynchronized(); | ||
298 | } | ||
299 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapperInterface.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapperInterface.php deleted file mode 100644 index eb8907f1..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapperInterface.php +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Validator\ViolationMapper; | ||
13 | |||
14 | use Symfony\Component\Form\FormInterface; | ||
15 | use Symfony\Component\Validator\ConstraintViolation; | ||
16 | |||
17 | /** | ||
18 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
19 | */ | ||
20 | interface ViolationMapperInterface | ||
21 | { | ||
22 | /** | ||
23 | * Maps a constraint violation to a form in the form tree under | ||
24 | * the given form. | ||
25 | * | ||
26 | * @param ConstraintViolation $violation The violation to map. | ||
27 | * @param FormInterface $form The root form of the tree | ||
28 | * to map it to. | ||
29 | * @param Boolean $allowNonSynchronized Whether to allow | ||
30 | * mapping to non-synchronized forms. | ||
31 | */ | ||
32 | public function mapViolation(ConstraintViolation $violation, FormInterface $form, $allowNonSynchronized = false); | ||
33 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationPath.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationPath.php deleted file mode 100644 index 06d09195..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationPath.php +++ /dev/null | |||
@@ -1,250 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Validator\ViolationMapper; | ||
13 | |||
14 | use Symfony\Component\Form\Exception\OutOfBoundsException; | ||
15 | use Symfony\Component\PropertyAccess\PropertyPath; | ||
16 | use Symfony\Component\PropertyAccess\PropertyPathInterface; | ||
17 | |||
18 | /** | ||
19 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
20 | */ | ||
21 | class ViolationPath implements \IteratorAggregate, PropertyPathInterface | ||
22 | { | ||
23 | /** | ||
24 | * @var array | ||
25 | */ | ||
26 | private $elements = array(); | ||
27 | |||
28 | /** | ||
29 | * @var array | ||
30 | */ | ||
31 | private $isIndex = array(); | ||
32 | |||
33 | /** | ||
34 | * @var array | ||
35 | */ | ||
36 | private $mapsForm = array(); | ||
37 | |||
38 | /** | ||
39 | * @var string | ||
40 | */ | ||
41 | private $pathAsString = ''; | ||
42 | |||
43 | /** | ||
44 | * @var integer | ||
45 | */ | ||
46 | private $length = 0; | ||
47 | |||
48 | /** | ||
49 | * Creates a new violation path from a string. | ||
50 | * | ||
51 | * @param string $violationPath The property path of a {@link ConstraintViolation} | ||
52 | * object. | ||
53 | */ | ||
54 | public function __construct($violationPath) | ||
55 | { | ||
56 | $path = new PropertyPath($violationPath); | ||
57 | $elements = $path->getElements(); | ||
58 | $data = false; | ||
59 | |||
60 | for ($i = 0, $l = count($elements); $i < $l; ++$i) { | ||
61 | if (!$data) { | ||
62 | // The element "data" has not yet been passed | ||
63 | if ('children' === $elements[$i] && $path->isProperty($i)) { | ||
64 | // Skip element "children" | ||
65 | ++$i; | ||
66 | |||
67 | // Next element must exist and must be an index | ||
68 | // Otherwise consider this the end of the path | ||
69 | if ($i >= $l || !$path->isIndex($i)) { | ||
70 | break; | ||
71 | } | ||
72 | |||
73 | $this->elements[] = $elements[$i]; | ||
74 | $this->isIndex[] = true; | ||
75 | $this->mapsForm[] = true; | ||
76 | } elseif ('data' === $elements[$i] && $path->isProperty($i)) { | ||
77 | // Skip element "data" | ||
78 | ++$i; | ||
79 | |||
80 | // End of path | ||
81 | if ($i >= $l) { | ||
82 | break; | ||
83 | } | ||
84 | |||
85 | $this->elements[] = $elements[$i]; | ||
86 | $this->isIndex[] = $path->isIndex($i); | ||
87 | $this->mapsForm[] = false; | ||
88 | $data = true; | ||
89 | } else { | ||
90 | // Neither "children" nor "data" property found | ||
91 | // Consider this the end of the path | ||
92 | break; | ||
93 | } | ||
94 | } else { | ||
95 | // Already after the "data" element | ||
96 | // Pick everything as is | ||
97 | $this->elements[] = $elements[$i]; | ||
98 | $this->isIndex[] = $path->isIndex($i); | ||
99 | $this->mapsForm[] = false; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | $this->length = count($this->elements); | ||
104 | |||
105 | $this->buildString(); | ||
106 | } | ||
107 | |||
108 | /** | ||
109 | * {@inheritdoc} | ||
110 | */ | ||
111 | public function __toString() | ||
112 | { | ||
113 | return $this->pathAsString; | ||
114 | } | ||
115 | |||
116 | /** | ||
117 | * {@inheritdoc} | ||
118 | */ | ||
119 | public function getLength() | ||
120 | { | ||
121 | return $this->length; | ||
122 | } | ||
123 | |||
124 | /** | ||
125 | * {@inheritdoc} | ||
126 | */ | ||
127 | public function getParent() | ||
128 | { | ||
129 | if ($this->length <= 1) { | ||
130 | return null; | ||
131 | } | ||
132 | |||
133 | $parent = clone $this; | ||
134 | |||
135 | --$parent->length; | ||
136 | array_pop($parent->elements); | ||
137 | array_pop($parent->isIndex); | ||
138 | array_pop($parent->mapsForm); | ||
139 | |||
140 | $parent->buildString(); | ||
141 | |||
142 | return $parent; | ||
143 | } | ||
144 | |||
145 | /** | ||
146 | * {@inheritdoc} | ||
147 | */ | ||
148 | public function getElements() | ||
149 | { | ||
150 | return $this->elements; | ||
151 | } | ||
152 | |||
153 | /** | ||
154 | * {@inheritdoc} | ||
155 | */ | ||
156 | public function getElement($index) | ||
157 | { | ||
158 | if (!isset($this->elements[$index])) { | ||
159 | throw new OutOfBoundsException(sprintf('The index %s is not within the violation path', $index)); | ||
160 | } | ||
161 | |||
162 | return $this->elements[$index]; | ||
163 | } | ||
164 | |||
165 | /** | ||
166 | * {@inheritdoc} | ||
167 | */ | ||
168 | public function isProperty($index) | ||
169 | { | ||
170 | if (!isset($this->isIndex[$index])) { | ||
171 | throw new OutOfBoundsException(sprintf('The index %s is not within the violation path', $index)); | ||
172 | } | ||
173 | |||
174 | return !$this->isIndex[$index]; | ||
175 | } | ||
176 | |||
177 | /** | ||
178 | * {@inheritdoc} | ||
179 | */ | ||
180 | public function isIndex($index) | ||
181 | { | ||
182 | if (!isset($this->isIndex[$index])) { | ||
183 | throw new OutOfBoundsException(sprintf('The index %s is not within the violation path', $index)); | ||
184 | } | ||
185 | |||
186 | return $this->isIndex[$index]; | ||
187 | } | ||
188 | |||
189 | /** | ||
190 | * Returns whether an element maps directly to a form. | ||
191 | * | ||
192 | * Consider the following violation path: | ||
193 | * | ||
194 | * <code> | ||
195 | * children[address].children[office].data.street | ||
196 | * </code> | ||
197 | * | ||
198 | * In this example, "address" and "office" map to forms, while | ||
199 | * "street does not. | ||
200 | * | ||
201 | * @param integer $index The element index. | ||
202 | * | ||
203 | * @return Boolean Whether the element maps to a form. | ||
204 | * | ||
205 | * @throws OutOfBoundsException If the offset is invalid. | ||
206 | */ | ||
207 | public function mapsForm($index) | ||
208 | { | ||
209 | if (!isset($this->mapsForm[$index])) { | ||
210 | throw new OutOfBoundsException(sprintf('The index %s is not within the violation path', $index)); | ||
211 | } | ||
212 | |||
213 | return $this->mapsForm[$index]; | ||
214 | } | ||
215 | |||
216 | /** | ||
217 | * Returns a new iterator for this path | ||
218 | * | ||
219 | * @return ViolationPathIterator | ||
220 | */ | ||
221 | public function getIterator() | ||
222 | { | ||
223 | return new ViolationPathIterator($this); | ||
224 | } | ||
225 | |||
226 | /** | ||
227 | * Builds the string representation from the elements. | ||
228 | */ | ||
229 | private function buildString() | ||
230 | { | ||
231 | $this->pathAsString = ''; | ||
232 | $data = false; | ||
233 | |||
234 | foreach ($this->elements as $index => $element) { | ||
235 | if ($this->mapsForm[$index]) { | ||
236 | $this->pathAsString .= ".children[$element]"; | ||
237 | } elseif (!$data) { | ||
238 | $this->pathAsString .= '.data'.($this->isIndex[$index] ? "[$element]" : ".$element"); | ||
239 | $data = true; | ||
240 | } else { | ||
241 | $this->pathAsString .= $this->isIndex[$index] ? "[$element]" : ".$element"; | ||
242 | } | ||
243 | } | ||
244 | |||
245 | if ('' !== $this->pathAsString) { | ||
246 | // remove leading dot | ||
247 | $this->pathAsString = substr($this->pathAsString, 1); | ||
248 | } | ||
249 | } | ||
250 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationPathIterator.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationPathIterator.php deleted file mode 100644 index 50baa453..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationPathIterator.php +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Validator\ViolationMapper; | ||
13 | |||
14 | use Symfony\Component\PropertyAccess\PropertyPathIterator; | ||
15 | |||
16 | /** | ||
17 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
18 | */ | ||
19 | class ViolationPathIterator extends PropertyPathIterator | ||
20 | { | ||
21 | public function __construct(ViolationPath $violationPath) | ||
22 | { | ||
23 | parent::__construct($violationPath); | ||
24 | } | ||
25 | |||
26 | public function mapsForm() | ||
27 | { | ||
28 | return $this->path->mapsForm($this->key()); | ||
29 | } | ||
30 | } | ||