8000 [Validator] New NodeTraverser implementation by webmozart · Pull Request #10287 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] New NodeTraverser implementation #10287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 86 commits into from
Mar 31, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
25cdc68
[Validator] Refactored ValidatorTest and ValidationVisitorTest into a…
webmozart Feb 12, 2014
a6ed4ca
[Validator] Prototype of the traverser implementation
webmozart Feb 17, 2014
a40189c
[Validator] Decoupled the new classes a bit
webmozart Feb 17, 2014
7e3a41d
[Validator] Moved visitors to NodeVisitor namespace
webmozart Feb 17, 2014
b1a9477
[Validator] Added ObjectInitializer visitor
webmozart Feb 17, 2014
1156bde
[Validator] Extracted code for group sequence resolving into GroupSeq…
webmozart Feb 17, 2014
321d5bb
[Validator] Throw exception if ObjectInitializer is constructed witho…
webmozart Feb 17, 2014
680f1ee
[Validator] Renamed $params to $parameters
webmozart Feb 17, 2014
8ae68c9
[Validator] Made tests green (yay!)
webmozart Feb 18, 2014
c1b1e03
[Validator] Added TODO reminder
webmozart Feb 18, 2014
5fbf848
[Validator] Added note about Callback constraint to CHANGELOG
webmozart Feb 18, 2014
8318286
[Validator] Completed GroupSequence implementation
webmozart Feb 18, 2014
f6b7288
[Validator] Removed unused use statement
webmozart Feb 18, 2014
4ea3ff6
[Validator] Finished inline documentation of ExecutionContext[Interface]
webmozart Feb 18, 2014
adc1437
[Validator] Fixed failing tests
webmozart Feb 18, 2014
499b2bb
[Validator] Completed test coverage of ExecutionContext
webmozart Feb 18, 2014
405a03b
[Validator] Updated deprecation notes in GroupSequence
webmozart Feb 18, 2014
9b07b0c
[Validator] Implemented BC validation of arrays through validate()
webmozart Feb 18, 2014
297ba4f
[Validator] Added a note why scalars are passed to cascadeObject() in…
webmozart Feb 18, 2014
09f744b
[Validator] Implemented BC traversal of traversables through validate()
webmozart Feb 18, 2014
ee1adad
[Validator] Implemented handling of arrays and Traversables in Legacy…
webmozart Feb 19, 2014
718601c
[Validator] Changed validateValue() to validate() in the new API
webmozart Feb 19, 2014
feb3d6f
[Validator] Tested the validation in a separate context
webmozart Feb 19, 2014
1e81f3b
[Validator] Finished test coverage and documentation of ExecutionCont…
webmozart Feb 19, 2014
9c9e715
[Validator] Completed documentation of GroupManagerInterface
webmozart Feb 19, 2014
2c65a28
[Validator] Completed test coverage and documentation of the Node cla…
webmozart Feb 19, 2014
a3555fb
[Validator] Fixed: Objects are not traversed unless they are instance…
webmozart Feb 19, 2014
bc29591
[Validator] Clearly separated classes supporting the API <2.5/2.5+
webmozart Feb 19, 2014
26eafa4
[Validator] Removed unused use statements
webmozart Feb 19, 2014
df41974
[Validator] Changed context manager to context factory
webmozart Feb 19, 2014
e440690
[Validator] Renamed validateCollection() to validateObjects()
webmozart Feb 19, 2014
e057b19
[Validator] Decoupled ContextRefresher from ExecutionContext
webmozart Feb 19, 2014
230f2a7
[Validator] Fixed exception message
webmozart Feb 19, 2014
cf1281f
[Validator] Added "Visitor" suffix to all node visitors
webmozart Feb 20, 2014
94583a9
[Validator] Changed NodeTraverser to traverse nodes iteratively, not …
webmozart Feb 20, 2014
117b1b9
[Validator] Wrapped collections into CollectionNode instances
webmozart Feb 20, 2014
51197f6
[Validator] Made traversal of Traversables consistent
webmozart Feb 20, 2014
08172bf
[Validator] Merged validate(), validateObject() and validateObjects()…
webmozart Feb 20, 2014
aeb6822
[Validator] Improved visitor names
webmozart Feb 20, 2014
4161371
[Validator] Removed unused use statements
webmozart Feb 20, 2014
76d8c9a
[Validator] Fixed typos
webmozart Feb 20, 2014
778ec24
[Validator] Removed helper class Traversal
webmozart Feb 20, 2014
6fc6ecd
[Validator] Fixed tests under PHP<5.3.9
webmozart Feb 20, 2014
2936d10
[Validator] Removed unused use statement
webmozart Feb 20, 2014
e8fa15b
[Validator] Fixed the new validator API under PHP < 5.3.9
webmozart Feb 20, 2014
8558377
[Validator] Added deprecation notes
webmozart Feb 20, 2014
dbce5a2
[Validator] Updated outdated doc blocks
webmozart Feb 20, 2014
822fe47
[Validator] Completed inline documentation of the Node classes and th…
webmozart Feb 21, 2014
186c115
[Validator] Improved test coverage of NonRecursiveNodeTraverser
webmozart Feb 21, 2014
299c2dc
[Validator] Improved test coverage and prevented duplicate validation…
webmozart Feb 21, 2014
be7f055
[Validator] Visitors may now abort the traversal by returning false f…
webmozart Feb 21, 2014
9986f03
[Validator] Added inline documentation for the PropertyPath utility c…
webmozart Feb 21, 2014
524a953
[Validator] Improved inline documentation of the validators
webmozart Feb 21, 2014
9ca61df
[Validator] Improved inline documentation of CascadingStrategy and Tr…
webmozart Feb 21, 2014
01ceeda
[Validator] Improved test coverage of the Traverse constraint
webmozart Feb 21, 2014
79387a7
[Validator] Improved inline documentation of the metadata classes
webmozart Feb 21, 2014
987313d
[Validator] Improved inline documentation of the violation builder
webmozart Feb 21, 2014
93fdff7
[Validator] The supported API versions can now be passed to the Valid…
webmozart Feb 21, 2014
886e05e
[Validator] Removed unused use statement
webmozart Feb 21, 2014
f61d31e
[Validator] Fixed grammar
webmozart Feb 21, 2014
23534ca
[Validator] Added a recursive clone of the new implementation for spe…
webmozart Feb 22, 2014
38e26fb
[Validator] Decoupled RecursiveContextualValidator from Node
webmozart Feb 22, 2014
274d4e6
[Validator] Changed ValidatorBuilder to always use LegacyExecutionCon…
webmozart Mar 11, 2014
eeed509
[Validator] Improved phpdoc of RecursiveValidator
webmozart Mar 11, 2014
5c479d8
[Validator] Simplified validateNodeForGroup
webmozart Mar 11, 2014
eed29d8
[Validator] Improved performance of *ContextualValidator::validate()
webmozart Mar 11, 2014
50bb84d
[Validator] Optimized RecursiveContextualValidator
webmozart Mar 11, 2014
be508e0
[Validator] Merged DefaultGroupReplacingVisitor and ContextUpdateVisi…
webmozart Mar 11, 2014
1622eb3
[Validator] Fixed reference to removed class in ValidatorBuilder
webmozart Mar 11, 2014
94ef21e
[Validator] Optimized use statements
webmozart Mar 17, 2014
73c9cc5
[Validator] Optimized performance by calling spl_object_hash() only o…
webmozart Mar 17, 2014
2f23d97
[Validator] Reduced number of method calls on the execution context
webmozart Mar 17, 2014
029a716
[Validator] Moved logic of replaceDefaultGroup() to validateNode()
webmozart Mar 17, 2014
3183aed
[Validator] Improved performance of cache key generation
webmozart Mar 17, 2014
90c27bb
[Validator] Removed traverser implementation
webmozart Mar 18, 2014
166d71a
[Validator] Removed unused property
webmozart Mar 18, 2014
7bc952d
[Validator] Improved inline documentation of RecursiveContextualValid…
webmozart Mar 18, 2014
1b111d0
[Validator] Fixed typos pointed out by @cordoval
webmozart Mar 18, 2014
0946dbe
[Validator] Adapted CHANGELOG
webmozart Mar 18, 2014
9b204c9
[FrameworkBundle] Implemented configuration to select the desired Val…
webmozart Mar 18, 2014
c5629bb
[Validator] Added getObject() to ExecutionContextInterface
webmozart Mar 18, 2014
3dc2b4d
[Validator] Made "symfony/property-access" an optional dependency
webmozart Mar 18, 2014
0bfde4a
[Validator] Fixed misnamed method calls in FrameworkExtension
webmozart Mar 18, 2014
b1badea
[Validator] Fixed failing CsrfFormLoginTest
webmozart Mar 30, 2014
68d8018
[Validator] Documented changes in the UPGRADE files 8000
webmozart Mar 30, 2014
ca6a722
[Validator] Converted `@deprecate` doc comment into regular doc comment
webmozart Mar 30, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Validator] Fixed the new validator API under PHP < 5.3.9
  • Loading branch information
webmozart committed Mar 30, 2014
commit e8fa15b27cf50af29fd1666371bfdcac851ee089
28 changes: 17 additions & 11 deletions src/Symfony/Component/Validator/Context/ExecutionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\Exception\BadMethodCallException;
use Symfony\Component\Validator\ExecutionContextInterface as LegacyExecutionContextInterface;
use Symfony\Component\Validator\Group\GroupManagerInterface;
use Symfony\Component\Validator\Mapping\PropertyMetadataInterface;
use Symfony\Component\Validator\Node\Node;
Expand All @@ -33,7 +32,7 @@
*
* @see ExecutionContextInterface
*/
class ExecutionContext implements ExecutionContextInterface, LegacyExecutionContextInterface, NodeObserverInterface
class ExecutionContext implements ExecutionContextInterface, NodeObserverInterface
{
/**
* @var ValidatorInterface
Expand Down Expand Up @@ -121,6 +120,13 @@ public function addViolation($message, array $parameters = array(), $invalidValu
// The parameters $invalidValue and following are ignored by the new
// API, as they are not present in the new interface anymore.
// You should use buildViolation() instead.
if (func_num_args() > 2) {
throw new BadMethodCallException(
'The parameters $invalidValue, $pluralization and $code are '.
'not supported anymore as of Symfony 2.5. Please use '.
'buildViolation() instead or enable the legacy mode.'
);
}

$this->violations->add(new ConstraintViolation(
$this->translator->trans($message, $parameters, $this->translationDomain),
Expand Down Expand Up @@ -235,8 +241,8 @@ public function getPropertyPath($subPath = '')
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $pluralization = null, $code = null)
{
throw new BadMethodCallException(
'addViolationAt() is not supported anymore in the new API. '.
'Please use buildViolation() or enable the legacy mode.'
'addViolationAt() is not supported anymore as of Symfony 2.5. '.
'Please use buildViolation() instead or enable the legacy mode.'
);
}

Expand All @@ -246,8 +252,8 @@ public function addViolationAt($subPath, $message, array $parameters = array(),
public function validate($value, $subPath = '', $groups = null, $traverse = false, $deep = false)
{
throw new BadMethodCallException(
'validate() is not supported anymore in the new API. '.
'Please use getValidator() or enable the legacy mode.'
'validate() is not supported anymore as of Symfony 2.5. '.
'Please use getValidator() instead or enable the legacy mode.'
);
}

Expand All @@ -257,8 +263,8 @@ public function validate($value, $subPath = '', $groups = null, $traverse = fals
public function validateValue($value, $constraints, $subPath = '', $groups = null)
{
throw new BadMethodCallException(
'validateValue() is not supported anymore in the new API. '.
'Please use getValidator() or enable the legacy mode.'
'validateValue() is not supported anymore as of Symfony 2.5. '.
'Please use getValidator() instead or enable the legacy mode.'
);
}

Expand All @@ -268,9 +274,9 @@ public function validateValue($value, $constraints, $subPath = '', $groups = nul
public function getMetadataFactory()
{
throw new BadMethodCallException(
'getMetadataFactory() is not supported anymore in the new API. '.
'Please use getMetadataFor() or hasMetadataFor() or enable the '.
'legacy mode.'
'getMetadataFactory() is not supported anymore as of Symfony 2.5. '.
'Please use getValidator() in combination with getMetadataFor() '.
'or hasMetadataFor() instead or enable the legacy mode.'
);
}
}
122 changes: 2 additions & 120 deletions src/Symfony/Component/Validator/Context/ExecutionContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\Validator\Constraints\GroupSequence;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\ExecutionContextInterface as LegacyExecutionContextInterface;
use Symfony\Component\Validator\Mapping\MetadataInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface;
Expand Down Expand Up @@ -59,16 +60,8 @@
* @since 2.5
* @author Bernhard Schussek <bschussek@gmail.com>
*/
interface ExecutionContextInterface
interface ExecutionContextInterface extends LegacyExecutionContextInterface
{
/**
* Adds a violation at the current node of the validation graph.
*
* @param string $message The error message
* @param array $parameters The parameters substituted in the error message
*/
public function addViolation($message, array $parameters = array());

/**
* Returns a builder for adding a violation with extended information.
*
Expand All @@ -88,13 +81,6 @@ public function addViolation($message, array $parameters = array());
*/
public function buildViolation($message, array $parameters = array());

/**
* Returns the violations generated in this context.
*
* @return ConstraintViolationListInterface The constraint violations
*/
public function getViolations();

/**
* Returns the validator.
*
Expand All @@ -114,108 +100,4 @@ public function getViolations();
* @return ValidatorInterface
*/
public function getValidator();

/**
* Returns the root value of the object graph.
*
* The validator, when given an object, traverses the properties and
* related objects and their properties. The root of the validation is the
* object at which the traversal started.
*
* The current value is returned by {@link getValue()}.
*
* @return mixed|null The root value of the validation or null, if no value
* is currently being validated
*/
public function getRoot();

/**
* Returns the value that the validator is currently validating.
*
* If you want to retrieve the object that was originally passed to the
* validator, use {@link getRoot()}.
*
* @return mixed|null The currently validated value or null, if no value is
* currently being validated
*/
public function getValue();

/**
* Returns the metadata for the currently validated value.
*
* With the core implementation, this method returns a
* {@link Mapping\ClassMetadata} instance if the current value is an object,
* a {@link Mapping\PropertyMetadata} instance if the current value is
* the value of a property and a {@link Mapping\GetterMetadata} instance if
* the validated value is the result of a getter method. The metadata can
* also be an {@link Mapping\GenericMetadata} if the current value does not
* belong to any structural element.
*
* @return MetadataInterface|null The metadata of the currently validated
* value or null, if no value is currently
* being validated
*/
public function getMetadata();

/**
* Returns the validation group that is currently being validated.
*
* @return string|GroupSequence|null The current validation group or null,
* if no value is currently being
* validated
*/
public function getGroup();

/**
* Returns the class name of the current node.
*
* If the metadata of the current node does not implement
* {@link ClassBasedInterface}, this method returns null.
*
* @return string|null The class name or null, if no class name could be
* found
*/
public function getClassName();

/**
* Returns the property name of the current node.
*
* If the metadata of the current node does not implement
* {@link PropertyMetadataInterface}, this method returns null.
*
* @return string|null The property name or null, if no property name could
* be found
*/
public function getPropertyName();

/**
* Returns the property path to the value that the validator is currently
* validating.
*
* For example, take the following object graph:
*
* (Person)---($address: Address)---($street: string)
*
* When the <tt>Person</tt> instance is passed to the validator, the
* property path is initially empty. When the <tt>$address</tt> property
* of that person is validated, the property path is "address". When
* the <tt>$street</tt> property of the related <tt>Address</tt> instance
* is validated, the property path is "address.street".
*
* Properties of objects are prefixed with a dot in the property path.
* Indices of arrays or objects implementing the {@link \ArrayAccess}
* interface are enclosed in brackets. For example, if the property in
* the previous example is <tt>$addresses</tt> and contains an array
* of <tt>Address</tt> instances, the property path generated for the
* <tt>$street</tt> property of one of these addresses is for example
* "addresses[0].street".
*
* @param string $subPath Optional. The suffix appended to the current
* property path
*
* @return string The current property path. The result may be an empty
* string if the validator is currently validating the
* root value of the validation graph
*/
public function getPropertyPath($subPath = '');
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Symfony\Component\Validator\Constraints\Traverse;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\Exception\InvalidArgumentException;
use Symfony\Component\Validator\ExecutionContextInterface as LegacyExecutionContextInterface;
use Symfony\Component\Validator\Group\GroupManagerInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface;
Expand All @@ -29,7 +28,7 @@
* @deprecated Implemented for backwards compatibility with Symfony < 2.5. To be
* removed in 3.0.
*/
class LegacyExecutionContext extends ExecutionContext implements LegacyExecutionContextInterface
class LegacyExecutionContext extends ExecutionContext
{
/**
* Creates a new context.
Expand Down Expand Up @@ -66,7 +65,7 @@ public function __construct(ValidatorInterface $validator, $root, GroupManagerIn
*/
public function addViolation($message, array $parameters = array(), $invalidValue = null, $pluralization = null, $code = null)
{
if (func_num_args() >= 3) {
if (func_num_args() > 2) {
$this
->buildViolation($message, $parameters)
->setInvalidValue($invalidValue)
Expand All @@ -86,7 +85,7 @@ public function addViolation($message, array $parameters = array(), $invalidValu
*/
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $pluralization = null, $code = null)
{
if (func_num_args() >= 3) {
if (func_num_args() > 2) {
$this
->buildViolation($message, $parameters)
->atPath($subPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@

class Validator2Dot5ApiTest extends Abstract2Dot5ApiTest
{
protected function setUp()
{
if (version_compare(PHP_VERSION, '5.3.9', '<')) {
$this->markTestSkipped('Not supported prior to PHP 5.3.9');
}

parent::setUp();
}

protected function createValidator(MetadataFactoryInterface $metadataFactory)
{
$nodeTraverser = new NodeTraverser($metadataFactory);
Expand Down
0