|
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\Validator; |
|
13 |
|
14 use Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface; |
|
15 |
|
16 /** |
|
17 * The central object representing a single validation process. |
|
18 * |
|
19 * This object is used by the GraphWalker to initialize validation of different |
|
20 * items and keep track of the violations. |
|
21 * |
|
22 * @author Fabien Potencier <fabien@symfony.com> |
|
23 * @author Bernhard Schussek <bernhard.schussek@symfony.com> |
|
24 * |
|
25 * @api |
|
26 */ |
|
27 class ExecutionContext |
|
28 { |
|
29 protected $root; |
|
30 protected $propertyPath; |
|
31 protected $class; |
|
32 protected $property; |
|
33 protected $group; |
|
34 protected $violations; |
|
35 protected $graphWalker; |
|
36 protected $metadataFactory; |
|
37 |
|
38 public function __construct( |
|
39 $root, |
|
40 GraphWalker $graphWalker, |
|
41 ClassMetadataFactoryInterface $metadataFactory |
|
42 ) |
|
43 { |
|
44 $this->root = $root; |
|
45 $this->graphWalker = $graphWalker; |
|
46 $this->metadataFactory = $metadataFactory; |
|
47 $this->violations = new ConstraintViolationList(); |
|
48 } |
|
49 |
|
50 public function __clone() |
|
51 { |
|
52 $this->violations = clone $this->violations; |
|
53 } |
|
54 |
|
55 /** |
|
56 * @api |
|
57 */ |
|
58 public function addViolation($message, array $params, $invalidValue) |
|
59 { |
|
60 $this->violations->add(new ConstraintViolation( |
|
61 $message, |
|
62 $params, |
|
63 $this->root, |
|
64 $this->propertyPath, |
|
65 $invalidValue |
|
66 )); |
|
67 } |
|
68 |
|
69 /** |
|
70 * @return ConstraintViolationList |
|
71 * |
|
72 * @api |
|
73 */ |
|
74 public function getViolations() |
|
75 { |
|
76 return $this->violations; |
|
77 } |
|
78 |
|
79 public function getRoot() |
|
80 { |
|
81 return $this->root; |
|
82 } |
|
83 |
|
84 public function setPropertyPath($propertyPath) |
|
85 { |
|
86 $this->propertyPath = $propertyPath; |
|
87 } |
|
88 |
|
89 public function getPropertyPath() |
|
90 { |
|
91 return $this->propertyPath; |
|
92 } |
|
93 |
|
94 public function setCurrentClass($class) |
|
95 { |
|
96 $this->class = $class; |
|
97 } |
|
98 |
|
99 public function getCurrentClass() |
|
100 { |
|
101 return $this->class; |
|
102 } |
|
103 |
|
104 public function setCurrentProperty($property) |
|
105 { |
|
106 $this->property = $property; |
|
107 } |
|
108 |
|
109 public function getCurrentProperty() |
|
110 { |
|
111 return $this->property; |
|
112 } |
|
113 |
|
114 public function setGroup($group) |
|
115 { |
|
116 $this->group = $group; |
|
117 } |
|
118 |
|
119 public function getGroup() |
|
120 { |
|
121 return $this->group; |
|
122 } |
|
123 |
|
124 /** |
|
125 * @return GraphWalker |
|
126 */ |
|
127 public function getGraphWalker() |
|
128 { |
|
129 return $this->graphWalker; |
|
130 } |
|
131 |
|
132 /** |
|
133 * @return ClassMetadataFactoryInterface |
|
134 */ |
|
135 public function getMetadataFactory() |
|
136 { |
|
137 return $this->metadataFactory; |
|
138 } |
|
139 } |