8000 [Validator] Finished inline documentation of ExecutionContext[Interface] · symfony/symfony@4ea3ff6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ea3ff6

Browse files
committed
[Validator] Finished inline documentation of ExecutionContext[Interface]
1 parent f6b7288 commit 4ea3ff6

File tree

4 files changed

+190
-59
lines changed

4 files changed

+190
-59
lines changed

src/Symfony/Component/Validator/Context/ExecutionContext.php

Lines changed: 80 additions & 18 deletions
< 8000 td data-grid-cell-id="diff-ffba2bed571e18a91782556cc0ca76152bcb556bd1a83590e733f4784e7c88f4-35-50-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,39 @@
2323
use Symfony\Component\Validator\Violation\ConstraintViolationBuilder;
2424

2525
/**
26-
* @since %%NextVersion%%
26+
* The context used and created by {@link ExecutionContextManager}.
27+
*
28+
* @since 2.5
2729
* @author Bernhard Schussek <bschussek@gmail.com>
30+
*
31+
* @see ExecutionContextInterface
2832
*/
2933
class ExecutionContext implements ExecutionContextInterface
3034
{
35+
/**
36+
* The root value of the validated object graph.
37+
*
38+
* @var mixed
39+
*/
3140
private $root;
3241

42+
/**
43+
* The violations generated in the current context.
44+
*
45+
* @var ConstraintViolationList
46+
*/
3347
private $violations;
3448

3549
/**
50+
* The current node under validation.
51+
*
3652
* @var Node
3753
*/
3854
private $node;
3955

4056
/**
57+
* The trace of nodes from the root node to the current node.
58+
*
4159
* @var \SplStack
4260
*/
4361
private $nodeStack;
@@ -73,25 +91,39 @@ public function __construct($root, ValidatorInterface $validator, GroupManagerIn
7391
$this->nodeStack = new \SplStack();
7492
}
7593

94+
/**
95+
* Sets the values of the context to match the given node.
96+
*
97+
* Internally, all nodes are stored on a stack and can be removed from that
98+
* stack using {@link popNode()}.
99+
*
100+
* @param Node $node The currently validated node
101+
*/
76102
public function pushNode(Node $node)
77103
{
78-
if (null !== $this->node) {
79-
$this->nodeStack->push($this->node);
80-
}
81-
104+
$this->nodeStack->push($node);
82105
$this->node = $node;
83106
}
84107

108+
/**
109+
* Sets the values of the context to match the previous node.
110+
*
111+
* The current node is removed from the internal stack and returned.
112+
*
113+
* @return Node|null The currently validated node or null, if no node was
114+
* on the stack
115+
*/
85116
public function popNode()
86117
{
87-
$poppedNode = $this->node;
88-
118+
// Nothing to do if the stack is empty
89119
if (0 === count($this->nodeStack)) {
90-
$this->node = null;
91-
92-
return $poppedNode;
120+
return null;
93121
}
94122

123+
$poppedNode = $this->node;
124+
125+
// After removing the last node, the stack is empty and the node
126+
// is null
95127
if (1 === count($this->nodeStack)) {
96128
$this->nodeStack->pop();
97129
$this->node = null;
@@ -105,6 +137,9 @@ public function popNode()
105137
return $poppedNode;
106138
}
107139

140+
/**
141+
* {@inheritdoc}
142+
*/
108143
public function addViolation($message, array $parameters = array())
109144
{
110145
$this->violations->add(new ConstraintViolation(
@@ -119,6 +154,9 @@ public function addViolation($message, array $parameters = array())
119154
));
120155
}
121156

157+
/**
158+
* {@inheritdoc}
159+
*/
122160
public function buildViolation($message, array $parameters = array())
123161
{
124162
return new ConstraintViolationBuilder(
@@ -133,57 +171,81 @@ public function buildViolation($message, array $parameters = array())
133171
);
134172
}
135173

174+
/**
175+
* {@inheritdoc}
176+
*/
136177
public function getViolations()
137178
{
138179
return $this->violations;
139180
}
140181

182+
/**
183+
* {@inheritdoc}
184+
*/
185+
public function getValidator()
186+
{
187+
return $this->validator;
188+
}
189+
190+
/**
191+
* {@inheritdoc}
192+
*/
141193
public function getRoot()
142194
{
143195
return $this->root;
144196
}
145197

198+
/**
199+
* {@inheritdoc}
200+
*/
146201
public function getValue()
147202
{
148203
return $this->node ? $this->node->value : null;
149204
}
150205

206+
/**
207+
* {@inheritdoc}
208+
*/
151209
public function getMetadata()
152210
{
153211
return $this->node ? $this->node->metadata : null;
154212
}
155213

214+
/**
215+
* {@inheritdoc}
216+
*/
156217
public function getGroup()
157218
{
158219
return $this->groupManager->getCurrentGroup();
159220
}
160221

222+
/**
223+
* {@inheritdoc}
224+
*/
161225
public function getClassName()
162226
{
163227
$metadata = $this->getMetadata();
164228

165229
return $metadata instanceof ClassBasedInterface ? $metadata->getClassName() : null;
166230
}
167231

232+
/**
233+
* {@inheritdoc}
234+
*/
168235
public function getPropertyName()
169236
{
170237
$metadata = $this->getMetadata();
171238

172239
return $metadata instanceof PropertyMetadataInterface ? $metadata->getPropertyName() : null;
173240
}
174241

242+
/**
243+
* {@inheritdoc}
244+
*/
175245
public function getPropertyPath($subPath = '')
176246
{
177247
$propertyPath = $this->node ? $this->node->propertyPath : '';
178248

179249
return PropertyPath::append($propertyPath, $subPath);
180250
}
181-
182-
/**
183-
* @return ValidatorInterface
184-
*/
185-
public function getValidator()
186-
{
187-
return $this->validator;
188-
}
189251
}

0 commit comments

Comments
 (0)
0