Permalink
Browse files

feature #10287 [WIP][Validator] New NodeTraverser implementation (web…

…mozart)

This PR was merged into the 2.5-dev branch.

Discussion
----------

[WIP][Validator] New NodeTraverser implementation

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | TODO
| License       | MIT
| Doc PR        | TODO

This PR is ready for review.

#### Todo

- [x] Test extensively to avoid regressions
- [x] Test more extensively
- [x] Finish inline documentation
- [x] Provide a layer to choose the desired API through ValidatorBuilder
- [x] Provide a layer to choose the desired API through FrameworkBundle
- [x] Update UPGRADE file
- [x] Update CHANGELOG
- [ ] Update user documentation

#### Goal

The goal of this PR is to be able to fix the following tickets:

- [x] #6138 Simplify adding of constraint violations
- [x] #7146 Support group sequences in Validator API
- [x] #7432 Poorly implemented Visitor Pattern
- [x] #8617 Control traversal on class level
- [x] #9888 Improve support for collection validation (PR: #9988)

The following tickets are probably fixed, but require testing first:

- [ ] #8376 Using validation_group causes error message to display multiple times
- [ ] #9939 GroupSequences still execute next group if first fail

Of course, full backwards compatibility **must** be guaranteed.

Other tickets I want to fix in follow-up PRs:

* #3622 Constraints\Valid does not respect "groups" option
* #4453 walk constraints by groups
* #7700 Propagate implicit group names in constraints
* #9051 Always ask value event if field isn't in the validating group
* #10163 poor collection validation test coverage
* #10221 TypeValidator does not enforce desired type when value is NULL
* #10495 Class Valid Constraint can't be used on a Form Type

#### In a nutshell

The implementation removes the Visitor pattern, which was implemented badly. I tried fixing it via a NodeTraverser/NodeVisitor implementation, but performance degraded too much so I decided to remove the pattern altogether.

A couple of new features and bug fixes are possible thanks to the new implementation. See below for details.

#### PHP Versions

PHP 5.3.8 and older does not allow to implement two different interfaces which both contain a method with the same name. This is used in the compatibility layer that supports both the old and the new API.

For this reason, the compatibility layer is disabled on PHP < 5.3.9. Older PHP versions need to decide on the old API or the new API (without compatibility layer).

#### Choosing the API Version

The API version can be specified by one of `Validation::API_VERSION_2_4`, `Validation::API_VERSION_2_5` and `Validation::API_VERSION_2_5_BC` to `setApiVersion()` when building the validator:

```php
// Old implementation
$validator = Validation::createValidatorBuilder()
    ->setApiVersion(Validation::API_VERSION_2_4)
    ->getValidator();

// New implementation with BC API
// Does not work on PHP < 5.3.9
$validator = Validation::createValidatorBuilder()
    ->setApiVersion(Validation::API_VERSION_2_5)
    ->getValidator();

// New implementation without BC API
$validator = Validation::createValidatorBuilder()
    ->setApiVersion(Validation::API_VERSION_2_5_BC)
    ->getValidator();
```

#### Features

##### Constraint validation as first-class citizen

The new API merges `validateValue()` and `validate()`. The idea is that the validation of values against constraints should be as simple as possible. Object validation is a special case where an object is tested against the `Valid` constraint. A backwards compatibility layer is provided to use both `validate()` and `validateValue()` with the old signature.

```php
// Validate against explicit constraints
$violations = $validator->validate($firstName, array(
    new NotNull(),
    new Length(array('min' => 3)),
));

// Validate against metadata
$violations = $validator->validate($object);

// Same, more expressive notation
$violations = $validator->validate($object, new Valid());

// Validate each entry against its metadata
$violations = $validator->validate($array);
```

##### Aggregate violations

It is now possible to call the methods of the validator multiple times and aggregate the violations to a common violation list. To do so, call `startContext()`, execute the calls and call `getViolations()` in the end to retrieve the violations:

```php
$violations = $validator->startContext()
    ->validate($title, new NotNull())
    ->validate($text, new NotNull())
    ->validate($author->getName(), new NotNull())
    ->getViolations()
```

Most of the time, you will want to specify a property path for each validation. Use the method `atPath()` for that:

```php
$violations = $validator->startContext()
    ->atPath('title')->validate($title, new NotNull())
    ->atPath('text')->validate($text, new NotNull())
    ->atPath('author.name')->validate($author->getName(), new NotNull())
    ->getViolations()
```

##### Control the context of nested validations

In Symfony <= 2.4, you can validate objects or constraints from within a constraint validator like this:

```php
$this->context->validate($object);
$this->context->validateValue($value, new Length(array('min' => 3)));
```

The validations will run and all violations will be added to the current context.

This way, it is impossible though to validate something, inspect the result and then decide what kind of violations to add to the context. This is needed, for example, for the `Some` constraint (proposed in #9888), which should succeed if any of the validated values did *not* generate violations.

For this reason, the new context API features a method `getValidator()`. This method returns the validator instance, you can use it to validate anything in a new context (as the validator always does):

```php
$validator = $this->context->getValidator();
$violations = $validator->validate($object);

if (count($violations)  > 0) {
    $this->context->addViolation('The validation did not pass');
}
```

You can also explicitly start a new context:

```php
$validator = $this->context->getValidator();
$violations = $validator->startContext()
    ->atPath('title')->validate($title, new NotNull())
    ->atPath('text')->validate($text, new NotNull())
    ->getViolations()
```

If you want to execute the validation in the current context, use the `inContext()` method of the validator instead:

```php
// violations are added to $this->context
$validator->inContext($this->context)
    ->atPath('title')->validate($title, new NotNull())
    ->atPath('text')->validate($text, new NotNull())
;
```

With this feature, #9888 (especially the PR for it: #9988) can be finished.

##### Custom group sequences (#7146)

It is now possible to pass `GroupSequence` instances whenever you can pass a group to the validator. For example:

```php
$violations = $validator->validate($object, new Valid(), new GroupSequence('Basic', 'Strict'));
```

Or in the context of the Form component:

```php
$form = $this->createForm(new BlogType(), new Blog(), array(
    'validation_groups' => new GroupSequence('Basic', 'Strict'),
));
```

##### Constraint violation builders (#6138)

The API for adding constraint violations was simplified:

```php
$this->context->addViolation('message', array('param' => 'value'));

// or

$this->context->buildViolation('message')
    ->atPath('property')
    ->setParameter('param', 'value')
    ->setTranslationDomain('validation_strict')
    ->addViolation();
```

##### Control traversal at class level (#8617)

Currently, it is possible whether to traverse a `Traversable` object or not in the `Valid` constraint:

```php
/**
 * @Assert\Valid(traverse=true)
 */
private $tags = new TagList();
```

(actually, `true` is the default)

In this way, the validator will iterate the `TagList` instance and validate each of the contained objects. You can also set "traverse" to `false` to disable iteration.

What if you want to specify, that `TagList` instances should always (or never) be traversed? That's currently not possible.

With this PR, you can do the following:

```php
/**
 * @Assert\Traverse(false)
 */
class TagList implements \IteratorAggregate
{
    // ...
}
```

#### Follow-up features

Features of the follow-up PRs will be described directly there.

#### Backwards compatibility

I implemented a new `AbstractValidatorTest` which tests both the old and the new implementation for compatibility. I still want to extend this test to make sure we don't introduce any regressions.

Almost none of the existing classes were modified (or only slightly). If users depend on the current (now "legacy") implementation, they will have the choice to continue using it until 3.0 (of course, without the new features).

#### Your task

Congrats, you made it till here :) If you have time, please skim over the code and give me feedback on the overall implementation and the class/method names. Again, no feedback on details yet, there are quite a few areas in the code that are still work in progress.

Thanks,
Bernhard

[1] That means that only the nodes from the root of the graph until the currently validated node are held in memory.

Commits
-------

ca6a722 [Validator] Converted `@deprecate` doc comment into regular doc comment
68d8018 [Validator] Documented changes in the UPGRADE files
b1badea [Validator] Fixed failing CsrfFormLoginTest
0bfde4a [Validator] Fixed misnamed method calls in FrameworkExtension
3dc2b4d [Validator] Made "symfony/property-access" an optional dependency
c5629bb [Validator] Added getObject() to ExecutionContextInterface
9b204c9 [FrameworkBundle] Implemented configuration to select the desired Validator API
0946dbe [Validator] Adapted CHANGELOG
1b111d0 [Validator] Fixed typos pointed out by @cordoval
7bc952d [Validator] Improved inline documentation of RecursiveContextualValidator
166d71a [Validator] Removed unused property
90c27bb [Validator] Removed traverser implementation
3183aed [Validator] Improved performance of cache key generation
029a716 [Validator] Moved logic of replaceDefaultGroup() to validateNode()
2f23d97 [Validator] Reduced number of method calls on the execution context
73c9cc5 [Validator] Optimized performance by calling spl_object_hash() only once per object
94ef21e [Validator] Optimized use statements
1622eb3 [Validator] Fixed reference to removed class in ValidatorBuilder
be508e0 [Validator] Merged DefaultGroupReplacingVisitor and ContextUpdateVisitor into NodeValidationVisitor
50bb84d [Validator] Optimized RecursiveContextualValidator
eed29d8 [Validator] Improved performance of *ContextualValidator::validate()
5c479d8 [Validator] Simplified validateNodeForGroup
eeed509 [Validator] Improved phpdoc of RecursiveValidator
274d4e6 [Validator] Changed ValidatorBuilder to always use LegacyExecutionContext
38e26fb [Validator] Decoupled RecursiveContextualValidator from Node
23534ca [Validator] Added a recursive clone of the new implementation for speed comparison
f61d31e [Validator] Fixed grammar
886e05e [Validator] Removed unused use statement
93fdff7 [Validator] The supported API versions can now be passed to the ValidatorBuilder
987313d [Validator] Improved inline documentation of the violation builder
79387a7 [Validator] Improved inline documentation of the metadata classes
01ceeda [Validator] Improved test coverage of the Traverse constraint
9ca61df [Validator] Improved inline documentation of CascadingStrategy and TraversalStrategy
524a953 [Validator] Improved inline documentation of the validators
9986f03 [Validator] Added inline documentation for the PropertyPath utility class
be7f055 [Validator] Visitors may now abort the traversal by returning false from beforeTraversal()
299c2dc [Validator] Improved test coverage and prevented duplicate validation of constraints
186c115 [Validator] Improved test coverage of NonRecursiveNodeTraverser
822fe47 [Validator] Completed inline documentation of the Node classes and the NodeTraverser
dbce5a2 [Validator] Updated outdated doc blocks
8558377 [Validator] Added deprecation notes
e8fa15b [Validator] Fixed the new validator API under PHP < 5.3.9
2936d10 [Validator] Removed unused use statement
6fc6ecd [Validator] Fixed tests under PHP<5.3.9
778ec24 [Validator] Removed helper class Traversal
76d8c9a [Validator] Fixed typos
4161371 [Validator] Removed unused use statements
aeb6822 [Validator] Improved visitor names
08172bf [Validator] Merged validate(), validateObject() and validateObjects() to simplify usage
51197f6 [Validator] Made traversal of Traversables consistent
117b1b9 [Validator] Wrapped collections into CollectionNode instances
94583a9 [Validator] Changed NodeTraverser to traverse nodes iteratively, not recursively
cf1281f [Validator] Added "Visitor" suffix to all node visitors
230f2a7 [Validator] Fixed exception message
e057b19 [Validator] Decoupled ContextRefresher from ExecutionContext
e440690 [Validator] Renamed validateCollection() to validateObjects()
df41974 [Validator] Changed context manager to context factory
26eafa4 [Validator] Removed unused use statements
bc29591 [Validator] Clearly separated classes supporting the API <2.5/2.5+
a3555fb [Validator] Fixed: Objects are not traversed unless they are instances of Traversable
2c65a28 [Validator] Completed test coverage and documentation of the Node classes
9c9e715 [Validator] Completed documentation of GroupManagerInterface
1e81f3b [Validator] Finished test coverage and documentation of ExecutionContextManager
feb3d6f [Validator] Tested the validation in a separate context
718601c [Validator] Changed validateValue() to validate() in the new API
ee1adad [Validator] Implemented handling of arrays and Traversables in LegacyExecutionContext::validate()
09f744b [Validator] Implemented BC traversal of traversables through validate()
297ba4f [Validator] Added a note why scalars are passed to cascadeObject() in NodeTraverser
9b07b0c [Validator] Implemented BC validation of arrays through validate()
405a03b [Validator] Updated deprecation notes in GroupSequence
499b2bb [Validator] Completed test coverage of ExecutionContext
adc1437 [Validator] Fixed failing tests
4ea3ff6 [Validator] Finished inline documentation of ExecutionContext[Interface]
f6b7288 [Validator] Removed unused use statement
8318286 [Validator] Completed GroupSequence implementation
5fbf848 [Validator] Added note about Callback constraint to CHANGELOG
c1b1e03 [Validator] Added TODO reminder
8ae68c9 [Validator] Made tests green (yay!)
680f1ee [Validator] Renamed $params to $parameters
321d5bb [Validator] Throw exception if ObjectInitializer is constructed without visitors
1156bde [Validator] Extracted code for group sequence resolving into GroupSequenceResolver
b1a9477 [Validator] Added ObjectInitializer visitor
7e3a41d [Validator] Moved visitors to NodeVisitor namespace
a40189c [Validator] Decoupled the new classes a bit
a6ed4ca [Validator] Prototype of the traverser implementation
25cdc68 [Validator] Refactored ValidatorTest and ValidationVisitorTest into an abstract validator test class
  • Loading branch information...
fabpot committed Mar 31, 2014
2 parents 880880b + ca6a722 commit bd577b11a253c483092310761746950ce243aa58
Showing with 7,309 additions and 1,361 deletions.
  1. +113 −0 UPGRADE-2.5.md
  2. +303 −0 UPGRADE-3.0.md
  3. +4 −2 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddValidatorInitializersPass.php
  4. +17 −0 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
  5. +39 −8 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
  6. +15 −0 src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
  7. +16 −41 src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml
  8. +2 −0 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
  9. +9 −0 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_2_4_api.php
  10. +9 −0 ...dle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_multiple_static_methods.php
  11. +9 −0 ...ony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_no_static_method.php
  12. +12 −0 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_2_4_api.xml
  13. +15 −0 ...dle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_multiple_static_methods.xml
  14. +12 −0 ...ony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_no_static_method.xml
  15. +5 −0 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_2_4_api.yml
  16. +5 −0 ...dle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_multiple_static_methods.yml
  17. +5 −0 ...ony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_no_static_method.yml
  18. +70 −26 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
  19. +54 −0 src/Symfony/Component/Validator/CHANGELOG.md
  20. +3 −0 src/Symfony/Component/Validator/ClassBasedInterface.php
  21. +1 −1 src/Symfony/Component/Validator/Constraint.php
  22. +2 −7 src/Symfony/Component/Validator/ConstraintValidatorFactory.php
  23. +37 −22 src/Symfony/Component/Validator/ConstraintViolation.php
  24. +1 −1 src/Symfony/Component/Validator/Constraints/Callback.php
  25. +17 −15 src/Symfony/Component/Validator/Constraints/CallbackValidator.php
  26. +32 −4 src/Symfony/Component/Validator/Constraints/ExpressionValidator.php
  27. +2 −2 src/Symfony/Component/Validator/Constraints/FileValidator.php
  28. +163 −5 src/Symfony/Component/Validator/Constraints/GroupSequence.php
  29. +1 −1 src/Symfony/Component/Validator/Constraints/Ip.php
  30. +54 −0 src/Symfony/Component/Validator/Constraints/Traverse.php
  31. +8 −2 src/Symfony/Component/Validator/Constraints/Valid.php
  32. +363 −0 src/Symfony/Component/Validator/Context/ExecutionContext.php
  33. +64 −0 src/Symfony/Component/Validator/Context/ExecutionContextFactory.php
  34. +37 −0 src/Symfony/Component/Validator/Context/ExecutionContextFactoryInterface.php
  35. +189 −0 src/Symfony/Component/Validator/Context/ExecutionContextInterface.php
  36. +156 −0 src/Symfony/Component/Validator/Context/LegacyExecutionContext.php
  37. +73 −0 src/Symfony/Component/Validator/Context/LegacyExecutionContextFactory.php
  38. +1 −1 src/Symfony/Component/Validator/DefaultTranslator.php
  39. +21 −0 src/Symfony/Component/Validator/Exception/OutOfBoundsException.php
  40. +20 −0 src/Symfony/Component/Validator/Exception/UnsupportedMetadataException.php
  41. +1 −1 src/Symfony/Component/Validator/Exception/ValidatorException.php
  42. +13 −10 src/Symfony/Component/Validator/ExecutionContext.php
  43. +38 −13 src/Symfony/Component/Validator/ExecutionContextInterface.php
  44. +3 −0 src/Symfony/Component/Validator/GlobalExecutionContextInterface.php
  45. +5 −19 src/Symfony/Component/Validator/Mapping/BlackholeMetadataFactory.php
  46. +1 −1 src/Symfony/Component/Validator/Mapping/Cache/DoctrineCache.php
  47. +53 −0 src/Symfony/Component/Validator/Mapping/CascadingStrategy.php
  48. +110 −31 src/Symfony/Component/Validator/Mapping/ClassMetadata.php
  49. +6 −92 src/Symfony/Component/Validator/Mapping/ClassMetadataFactory.php
  50. +80 −0 src/Symfony/Component/Validator/Mapping/ClassMetadataInterface.php
  51. +9 −92 src/Symfony/Component/Validator/Mapping/ElementMetadata.php
  52. +40 −0 src/Symfony/Component/Validator/Mapping/Factory/BlackHoleMetadataFactory.php
  53. +165 −0 src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php
  54. +24 −0 src/Symfony/Component/Validator/Mapping/Factory/MetadataFactoryInterface.php
  55. +248 −0 src/Symfony/Component/Validator/Mapping/GenericMetadata.php
  56. +17 −0 src/Symfony/Component/Validator/Mapping/GetterMetadata.php
  57. +1 −1 src/Symfony/Component/Validator/Mapping/Loader/AbstractLoader.php
  58. +3 −3 src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php
  59. +1 −1 src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php
  60. +74 −41 src/Symfony/Component/Validator/Mapping/MemberMetadata.php
  61. +51 −0 src/Symfony/Component/Validator/Mapping/MetadataInterface.php
  62. +13 −0 src/Symfony/Component/Validator/Mapping/PropertyMetadata.php
  63. +36 −0 src/Symfony/Component/Validator/Mapping/PropertyMetadataInterface.php
  64. +65 −0 src/Symfony/Component/Validator/Mapping/TraversalStrategy.php
  65. +9 −6 src/Symfony/Component/Validator/MetadataFactoryInterface.php
  66. +11 −6 src/Symfony/Component/Validator/MetadataInterface.php
  67. +3 −0 src/Symfony/Component/Validator/PropertyMetadataContainerInterface.php
  68. +3 −0 src/Symfony/Component/Validator/PropertyMetadataInterface.php
  69. +2 −3 src/Symfony/Component/Validator/Tests/Constraints/AllValidatorTest.php
  70. +34 −2 src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php
  71. +2 −2 src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php
  72. +4 −4 src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php
  73. +1 −1 src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php
  74. +1 −1 src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php
  75. +1 −1 src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php
  76. +84 −0 src/Symfony/Component/Validator/Tests/Constraints/GroupSequenceTest.php
  77. +1 −1 src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php
  78. +2 −2 src/Symfony/Component/Validator/Tests/ExecutionContextTest.php
  79. +7 −1 src/Symfony/Component/Validator/Tests/Fixtures/Entity.php
  80. +26 −0 src/Symfony/Component/Validator/Tests/Fixtures/FakeClassMetadata.php
  81. +20 −4 src/Symfony/Component/Validator/Tests/Fixtures/FakeMetadataFactory.php
  82. +4 −4 src/Symfony/Component/Validator/Tests/Fixtures/GroupSequenceProviderEntity.php
  83. +20 −0 src/Symfony/Component/Validator/Tests/Fixtures/LegacyClassMetadata.php
  84. +13 −0 src/Symfony/Component/Validator/Tests/Fixtures/Reference.php
  85. +1 −1 src/Symfony/Component/Validator/Tests/Mapping/Cache/DoctrineCacheTest.php
  86. +2 −3 src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataFactoryTest.php
  87. +0 −2 src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php
  88. +1 −1 src/Symfony/Component/Validator/Tests/Mapping/ElementMetadataTest.php
  89. +1 −1 src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php
  90. +1 −1 src/Symfony/Component/Validator/Tests/Mapping/Loader/FilesLoaderTest.php
  91. +1 −1 src/Symfony/Component/Validator/Tests/Mapping/Loader/XmlFileLoaderTest.php
  92. +1 −1 src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php
  93. +3 −3 src/Symfony/Component/Validator/Tests/Mapping/MemberMetadataTest.php
  94. +0 −564 src/Symfony/Component/Validator/Tests/ValidationVisitorTest.php
  95. +681 −0 src/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.php
  96. +245 −0 src/Symfony/Component/Validator/Tests/Validator/AbstractLegacyApiTest.php
  97. +1,209 −0 src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php
  98. +37 −0 src/Symfony/Component/Validator/Tests/Validator/LegacyValidator2Dot5ApiTest.php
  99. +37 −0 src/Symfony/Component/Validator/Tests/Validator/LegacyValidatorLegacyApiTest.php
  100. +28 −0 src/Symfony/Component/Validator/Tests/Validator/RecursiveValidator2Dot5ApiTest.php
  101. +34 −0 src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php
  102. +10 −250 src/Symfony/Component/Validator/Tests/ValidatorTest.php
  103. +57 −0 src/Symfony/Component/Validator/Util/PropertyPath.php
  104. +16 −0 src/Symfony/Component/Validator/Validation.php
  105. +4 −1 src/Symfony/Component/Validator/ValidationVisitor.php
  106. +7 −0 src/Symfony/Component/Validator/ValidationVisitorInterface.php
  107. +13 −2 src/Symfony/Component/Validator/Validator.php
  108. +89 −0 src/Symfony/Component/Validator/Validator/ContextualValidatorInterface.php
  109. +79 −0 src/Symfony/Component/Validator/Validator/LegacyValidator.php
  110. +804 −0 src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php
  111. +129 −0 src/Symfony/Component/Validator/Validator/RecursiveValidator.php
  112. +100 −0 src/Symfony/Component/Validator/Validator/ValidatorInterface.php
  113. +80 −14 src/Symfony/Component/Validator/ValidatorBuilder.php
  114. +48 −33 src/Symfony/Component/Validator/ValidatorBuilderInterface.php
  115. +15 −0 src/Symfony/Component/Validator/ValidatorInterface.php
  116. +201 −0 src/Symfony/Component/Validator/Violation/ConstraintViolationBuilder.php
  117. +108 −0 src/Symfony/Component/Validator/Violation/ConstraintViolationBuilderInterface.php
  118. +3 −2 src/Symfony/Component/Validator/composer.json
View
@@ -101,6 +101,7 @@ Validator
valid. This is the default behaviour.
Strict email validation has to be explicitly activated in the configuration file by adding
+
```
framework:
//...
@@ -109,7 +110,119 @@ Validator
//...
```
+
Also you have to add to your composer.json:
+
```
"egulias/email-validator": "1.1.*"
```
+
+ * `ClassMetadata::getGroupSequence()` now returns `GroupSequence` instances
+ instead of an array. The sequence implements `\Traversable`, `\ArrayAccess`
+ and `\Countable`, so in most cases you should be fine. If you however use the
+ sequence with PHP's `array_*()` functions, you should cast it to an array
+ first using `iterator_to_array()`:
+
+ Before:
+
+ ```
+ $sequence = $metadata->getGroupSequence();
+ $result = array_map($callback, $sequence);
+ ```
+
+ After:
+
+ ```
+ $sequence = iterator_to_array($metadata->getGroupSequence());
+ $result = array_map($callback, $sequence);
+ ```
+
+ * The array type hint in `ClassMetadata::setGroupSequence()` was removed. If
+ you overwrite this method, make sure to remove the type hint as well. The
+ method should now accept `GroupSequence` instances just as well as arrays.
+
+ Before:
+
+ ```
+ public function setGroupSequence(array $groups)
+ {
+ // ...
+ }
+ ```
+
+ After:
+
+ ```
+ public function setGroupSequence($groupSequence)
+ {
+ // ...
+ }
+ ```
+
+ * The validation engine in `Symfony\Component\Validator\Validator` was replaced
+ by a new one in `Symfony\Component\Validator\Validator\RecursiveValidator`.
+ With that change, several classes were deprecated that will be removed in
+ Symfony 3.0. Also, the API of the validator was slightly changed. More
+ details about that can be found in UPGRADE-3.0.
+
+ You can choose the desired API via the new "api" entry in
+ app/config/config.yml:
+
+ ```
+ framework:
+ validation:
+ enabled: true
+ api: auto
+ ```
+
+ When running PHP 5.3.9 or higher, Symfony will then use an implementation
+ that supports both the old API and the new one:
+
+ ```
+ framework:
+ validation:
+ enabled: true
+ api: 2.5-bc
+ ```
+
+ When running PHP lower than 5.3.9, that compatibility layer is not supported.
+ On those versions, the old implementation will be used instead:
+
+ ```
+ framework:
+ validation:
+ enabled: true
+ api: 2.4
+ ```
+
+ If you develop a new application that doesn't rely on the old API, you can
+ also set the API to 2.5. In that case, the backwards compatibility layer
+ will not be activated:
+
+ ```
+ framework:
+ validation:
+ enabled: true
+ api: 2.5
+ ```
+
+ When using the validator outside of the Symfony full-stack framework, the
+ desired API can be selected using `setApiVersion()` on the validator builder:
+
+ ```
+ // Previous implementation
+ $validator = Validation::createValidatorBuilder()
+ ->setApiVersion(Validation::API_VERSION_2_4)
+ ->getValidator();
+
+ // New implementation with backwards compatibility support
+ $validator = Validation::createValidatorBuilder()
+ ->setApiVersion(Validation::API_VERSION_2_5_BC)
+ ->getValidator();
+
+ // New implementation without backwards compatibility support
+ $validator = Validation::createValidatorBuilder()
+ ->setApiVersion(Validation::API_VERSION_2_5)
+ ->getValidator();
+ ```
+
Oops, something went wrong.

0 comments on commit bd577b1

Please sign in to comment.