Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 23534ca

Browse files
committed
[Validator] Added a recursive clone of the new implementation for speed comparison
1 parent f61d31e commit 23534ca

21 files changed

+1004
-225
lines changed

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

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Validator\ConstraintViolationList;
1818
use Symfony\Component\Validator\Exception\BadMethodCallException;
1919
use Symfony\Component\Validator\Group\GroupManagerInterface;
20+
use Symfony\Component\Validator\Mapping\MetadataInterface;
2021
use Symfony\Component\Validator\Mapping\PropertyMetadataInterface;
2122
use Symfony\Component\Validator\Node\Node;
2223
use Symfony\Component\Validator\Util\PropertyPath;
@@ -48,11 +49,6 @@ class ExecutionContext implements ExecutionContextInterface
4849
*/
4950
private $root;
5051

51-
/**
52-
* @var GroupManagerInterface
53-
*/
54-
private $groupManager;
55-
5652
/**
5753
* @var TranslatorInterface
5854
*/
@@ -71,11 +67,32 @@ class ExecutionContext implements ExecutionContextInterface
7167
private $violations;
7268

7369
/**
74-
* The current node under validation.
70+
* The currently validated value.
71+
*
72+
* @var mixed
73+
*/
74+
private $value;
75+
76+
/**
77+
* The property path leading to the current value.
78+
*
79+
* @var string
80+
*/
81+
private $propertyPath = '';
82+
83+
/**
84+
* The current validation metadata.
85+
*
86+
* @var MetadataInterface
87+
*/
88+
private $metadata;
89+
90+
/**
91+
* The currently validated group.
7592
*
76-
* @var Node
93+
* @var string|null
7794
*/
78-
private $node;
95+
private $group;
7996

8097
/**
8198
* Stores which objects have been validated in which group.
@@ -104,9 +121,6 @@ class ExecutionContext implements ExecutionContextInterface
104121
* @param ValidatorInterface $validator The validator
105122
* @param mixed $root The root value of the
106123
* validated object graph
107-
* @param GroupManagerInterface $groupManager The manager for accessing
108-
* the currently validated
109-
* group
110124
* @param TranslatorInterface $translator The translator
111125
* @param string|null $translationDomain The translation domain to
112126
* use for translating
@@ -115,24 +129,45 @@ class ExecutionContext implements ExecutionContextInterface
115129
* @internal Called by {@link ExecutionContextFactory}. Should not be used
116130
* in user code.
117131
*/
118-
public function __construct(ValidatorInterface $validator, $root, GroupManagerInterface $groupManager, TranslatorInterface $translator, $translationDomain = null)
132+
public function __construct(ValidatorInterface $validator, $root, TranslatorInterface $translator, $translationDomain = null)
119133
{
120134
$this->validator = $validator;
121135
$this->root = $root;
122-
$this->groupManager = $groupManager;
123136
$this->translator = $translator;
124137
$this->translationDomain = $translationDomain;
125138
$this->violations = new ConstraintViolationList();
126139
}
127140

128141
/**
129-
* Sets the values of the context to match the given node.
130-
*
131-
* @param Node $node The currently validated node
142+
* {@inheritdoc}
143+
*/
144+
public function setValue($value)
145+
{
146+
$this->value = $value;
147+
}
148+
149+
/**
150+
* {@inheritdoc}
151+
*/
152+
public function setMetadata(MetadataInterface $metadata = null)
153+
{
154+
$this->metadata = $metadata;
155+
}
156+
157+
/**
158+
* {@inheritdoc}
159+
*/
160+
public function setPropertyPath($propertyPath)
161+
{
162+
$this->propertyPath = (string) $propertyPath;
163+
}
164+
165+
/**
166+
* {@inheritdoc}
132167
*/
133-
public function setCurrentNode(Node $node)
168+
public function setGroup($group)
134169
{
135-
$this->node = $node;
170+
$this->group = $group;
136171
}
137172

138173
/**
@@ -209,53 +244,47 @@ public function getRoot()
209244
*/
210245
public function getValue()
211246
{
212-
return $this->node ? $this->node->value : null;
247+
return $this->value;
213248
}
214249

215250
/**
216251
* {@inheritdoc}
217252
*/
218253
public function getMetadata()
219254
{
220-
return $this->node ? $this->node->metadata : null;
255+
return $this->metadata;
221256
}
222257

223258
/**
224259
* {@inheritdoc}
225260
*/
226261
public function getGroup()
227262
{
228-
return $this->groupManager->getCurrentGroup();
263+
return $this->group;
229264
}
230265

231266
/**
232267
* {@inheritdoc}
233268
*/
234269
public function getClassName()
235270
{
236-
$metadata = $this->getMetadata();
237-
238-
return $metadata instanceof ClassBasedInterface ? $metadata->getClassName() : null;
271+
return $this->metadata instanceof ClassBasedInterface ? $this->metadata->getClassName() : null;
239272
}
240273

241274
/**
242275
* {@inheritdoc}
243276
*/
244277
public function getPropertyName()
245278
{
246-
$metadata = $this->getMetadata();
247-
248-
return $metadata instanceof PropertyMetadataInterface ? $metadata->getPropertyName() : null;
279+
return $this->metadata instanceof PropertyMetadataInterface ? $this->metadata->getPropertyName() : null;
249280
}
250281

251282
/**
252283
* {@inheritdoc}
253284
*/
254285
public function getPropertyPath($subPath = '')
255286
{
256-
$propertyPath = $this->node ? $this->node->propertyPath : '';
257-
258-
return PropertyPath::append($propertyPath, $subPath);
287+
return PropertyPath::append($this->propertyPath, $subPath);
259288
}
260289

261290
/**

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
*/
2727
class ExecutionContextFactory implements ExecutionContextFactoryInterface
2828
{
29-
/**
30-
* @var GroupManagerInterface
31-
*/
32-
private $groupManager;
33-
3429
/**
3530
* @var TranslatorInterface
3631
*/
@@ -44,17 +39,13 @@ class ExecutionContextFactory implements ExecutionContextFactoryInterface
4439
/**
4540
* Creates a new context factory.
4641
*
47-
* @param GroupManagerInterface $groupManager The manager for accessing
48-
* the currently validated
49-
* group
5042
* @param TranslatorInterface $translator The translator
5143
* @param string|null $translationDomain The translation domain to
5244
* use for translating
5345
* violation messages
5446
*/
55-
public function __construct(GroupManagerInterface $groupManager, TranslatorInterface $translator, $translationDomain = null)
47+
public function __construct(TranslatorInterface $translator, $translationDomain = null)
5648
{
57-
$this->groupManager = $groupManager;
5849
$this->translator = $translator;
5950
$this->translationDomain = $translationDomain;
6051
}
@@ -67,7 +58,6 @@ public function createContext(ValidatorInterface $validator, $root)
6758
return new ExecutionContext(
6859
$validator,
6960
$root,
70-
$this->groupManager,
7161
$this->translator,
7262
$this->translationDomain
7363
);

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Validator\Context;
1313

1414
use Symfony\Component\Validator\ExecutionContextInterface as LegacyExecutionContextInterface;
15+
use Symfony\Component\Validator\Mapping\MetadataInterface;
1516
use Symfony\Component\Validator\Node\Node;
1617
use Symfony\Component\Validator\Validator\ValidatorInterface;
1718
use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface;
@@ -100,14 +101,44 @@ public function buildViolation($message, array $parameters = array());
100101
public function getValidator();
101102

102103
/**
103-
* Sets the currently traversed node.
104+
* Sets the currently validated value.
104105
*
105-
* @param Node $node The current node
106+
* @param mixed $value The validated value
106107
*
107108
* @internal Used by the validator engine. Should not be called by user
108109
* code.
109110
*/
110-
public function setCurrentNode(Node $node);
111+
public function setValue($value);
112+
113+
/**
114+
* Sets the current validation metadata.
115+
*
116+
* @param MetadataInterface $metadata The validation metadata
117+
*
118+
* @internal Used by the validator engine. Should not be called by user
119+
* code.
120+
*/
121+
public function setMetadata(MetadataInterface $metadata = null);
122+
123+
/**
124+
* Sets the property path leading to the current value.
125+
*
126+
* @param string $propertyPath The property path to the current value
127+
*
128+
* @internal Used by the validator engine. Should not be called by user
129+
* code.
130+
*/
131+
public function setPropertyPath($propertyPath);
132+
133+
/**
134+
* Sets the currently validated group.
135+
*
136+
* @param string|null $group The validated group
137+
*
138+
* @internal Used by the validator engine. Should not be called by user
139+
* code.
140+
*/
141+
public function setGroup($group);
111142

112143
/**
113144
* Marks an object as validated in a specific validation group.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class LegacyExecutionContext extends ExecutionContext
4242
* @internal Called by {@link LegacyExecutionContextFactory}. Should not be used
4343
* in user code.
4444
*/
45-
public function __construct(ValidatorInterface $validator, $root, GroupManagerInterface $groupManager, TranslatorInterface $translator, $translationDomain = null)
45+
public function __construct(ValidatorInterface $validator, $root, TranslatorInterface $translator, $translationDomain = null)
4646
{
4747
if (!$validator instanceof LegacyValidatorInterface) {
4848
throw new InvalidArgumentException(
@@ -54,7 +54,6 @@ public function __construct(ValidatorInterface $validator, $root, GroupManagerIn
5454
parent::__construct(
5555
$validator,
5656
$root,
57-
$groupManager,
5857
$translator,
5958
$translationDomain
6059
);

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
*/
2727
class LegacyExecutionContextFactory implements ExecutionContextFactoryInterface
2828
{
29-
/**
30-
* @var GroupManagerInterface
31-
*/
32-
private $groupManager;
33-
3429
/**
3530
* @var TranslatorInterface
3631
*/
@@ -44,17 +39,13 @@ class LegacyExecutionContextFactory implements ExecutionContextFactoryInterface
4439
/**
4540
* Creates a new context factory.
4641
*
47-
* @param GroupManagerInterface $groupManager The manager for accessing
48-
* the currently validated
49-
* group
5042
* @param TranslatorInterface $translator The translator
5143
* @param string|null $translationDomain The translation domain to
5244
* use for translating
5345
* violation messages
5446
*/
55-
public function __construct(GroupManagerInterface $groupManager, TranslatorInterface $translator, $translationDomain = null)
47+
public function __construct(TranslatorInterface $translator, $translationDomain = null)
5648
{
57-
$this->groupManager = $groupManager;
5849
$this->translator = $translator;
5950
$this->translationDomain = $translationDomain;
6051
}
@@ -67,7 +58,6 @@ public function createContext(ValidatorInterface $validator, $root)
6758
return new LegacyExecutionContext(
6859
$validator,
6960
$root,
70-
$this->groupManager,
7161
$this->translator,
7262
$this->translationDomain
7363
);

src/Symfony/Component/Validator/Group/GroupManagerInterface.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Symfony/Component/Validator/NodeVisitor/ContextUpdateVisitor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class ContextUpdateVisitor extends AbstractVisitor
3030
*/
3131
public function visit(Node $node, ExecutionContextInterface $context)
3232
{
33-
$context->setCurrentNode($node);
33+
$context->setValue($node->value);
34+
$context->setMetadata($node->metadata);
35+
$context->setPropertyPath($node->propertyPath);
3436
}
3537
}

0 commit comments

Comments
 (0)