Commit Graph

17167 Commits

Author SHA1 Message Date
Bernhard Schussek
f3e172f6e5 [Form] Improved test coverage of UrlType 2014-04-09 05:11:36 +02:00
Fabien Potencier
9a95f520c9 bug #10649 [BrowserKit] Fix #10641 : BrowserKit is broken when using ip as host (romainneutron)
This PR was merged into the 2.3 branch.

Discussion
----------

[BrowserKit] Fix #10641 : BrowserKit is broken when using ip as host

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

As documented in http://php.net/manual/en/function.preg-replace.php, we have to use the `$` notation for replacing the backreference

>When working with a replacement pattern where a backreference is immediately followed by another number (i.e.: placing a literal number immediately after a matched pattern), you cannot use the familiar \\1 notation for your backreference. \\11, for example, would confuse preg_replace() since it does not know whether you want the \\1 backreference followed by a literal 1, or the \\11 backreference followed by nothing. In this case the solution is to use \${1}1. This creates an isolated $1 backreference, leaving the 1 as a literal.

Commits
-------

e946da3 [BrowserKit] Fix #10641 : BrowserKit is broken when using ip as host
2014-04-09 05:10:38 +02:00
Tobias Schultze
05ea19a4bf [HttpFoundation] use MERGE SQL for MS SQL Server session storage 2014-04-08 22:01:45 +02:00
Tobias Schultze
e58d7cf6c6 [HttpFoundation] fix PDO session handler under high concurrency 2014-04-08 21:48:40 +02:00
Romain Neutron
e946da303d [BrowserKit] Fix #10641 : BrowserKit is broken when using ip as host 2014-04-08 15:30:36 +02:00
Fabien Potencier
5e6c089b71 Merge branch '2.4'
* 2.4:
  bumped Symfony version to 2.4.4
  updated VERSION for 2.4.3
  updated CHANGELOG for 2.4.3
  bumped Symfony version to 2.3.13
  updated VERSION for 2.3.12
  update CONTRIBUTORS for 2.3.12
  updated CHANGELOG for 2.3.12

Conflicts:
	src/Symfony/Component/HttpKernel/Kernel.php
2014-04-05 18:03:59 +02:00
Fabien Potencier
43ee21ea2c Merge branch '2.3' into 2.4
* 2.3:
  bumped Symfony version to 2.3.13
  updated VERSION for 2.3.12
  update CONTRIBUTORS for 2.3.12
  updated CHANGELOG for 2.3.12

Conflicts:
	src/Symfony/Component/HttpKernel/Kernel.php
2014-04-05 18:03:39 +02:00
Fabien Potencier
40db85d9da bumped Symfony version to 2.4.4 2014-04-05 13:49:17 +02:00
Fabien Potencier
3199b2e0d1 updated VERSION for 2.4.3 2014-04-04 12:27:02 +02:00
Fabien Potencier
4e777dfc1b updated CHANGELOG for 2.4.3 2014-04-04 11:31:00 +02:00
Fabien Potencier
2a61b5fe77 Merge branch '2.4'
* 2.4:
2014-04-04 11:27:51 +02:00
Fabien Potencier
c4404f6e64 reverted accidental merge of master
* origin/2.4: (204 commits)
  Revert PHPUnit version, revert APC configuration
  removed APC on the CLI for Travis as it does not work well with PHPUnit and Composer anyway
  [Security] Replace exception mocks with actual exception instances.
  Remove an unused argument.
  Use `Filesystem::chmod` instead of `chmod` when dumping file
  [Form] Added test for disabling buttons
  [Form] Added check for parent disabled status in Button form elements
  [Process] Fix Process test suite
  Fixes URL validator to accept single part urls
  [Form] Fixed infinite tests when ICU is available
  tweaked Travis configuration to get more tests running
  fixed float comparison in unit tests for HHVM
  upgraded PHPUnit to version 4 for better HHVM support
  [Process] fixed HHVM usage on the CLI
  Fix class names in ApcUniversalClassLoader tests.
  fixed the profiler when an uncalled listener throws an exception when instantiated
  fixed CS
  Added test case for 4c6a2d15095c13b2a35751b2b2712b183be489c4
  Fixed bug in ChoiceType triggering a warning when not using utf-8
  fixed typos
  ...
2014-04-04 11:27:09 +02:00
Fabien Potencier
27035b4661 minor #10632 [FrameworkBundle] Fix tests (jakzal)
This PR was merged into the 2.5-dev branch.

Discussion
----------

[FrameworkBundle] Fix tests

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

This [fixes the build](https://travis-ci.org/jakzal/symfony/builds/22199535) [![Build Status](https://travis-ci.org/jakzal/symfony.svg?branch=framework-bundle-tests-fix)](https://travis-ci.org/jakzal/symfony) by only initializing a fully configured validation service if APC is available. At the moment we only provide ApcCache for mapping' caching (out of the box). DoctrineCache is available but not configured. I also added an additional test case to verify that a validation service can be created on php >=5.5.

Commits
-------

009c4b8 [FrameworkBundle] Only initialize a fully configured service if APC is available.
2014-04-03 21:17:37 +02:00
Jakub Zalas
009c4b8451 [FrameworkBundle] Only initialize a fully configured service if APC is available.
At the moment we only provide ApcCache for mapping caching (out of the box). DoctrineCache is available but not configured.
2014-04-03 17:10:06 +01:00
Fabien Potencier
bc6020d8d7 bug #10629 [DependencyInjection] Fix #10626, use better check on attribute existence and values on XML load (romainneutron)
This PR was merged into the 2.5-dev branch.

Discussion
----------

[DependencyInjection] Fix #10626, use better check on attribute existence and values on XML load

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

Commits
-------

8163427 [DependencyInjection] Fix #10626, use better check on attribute existence and values on XML load
2014-04-03 17:02:32 +02:00
Romain Neutron
8163427b71 [DependencyInjection] Fix #10626, use better check on attribute existence and values on XML load 2014-04-03 14:00:33 +02:00
Fabien Potencier
a18ee423f9 bumped Symfony version to 2.3.13 2014-04-03 10:18:27 +02:00
Fabien Potencier
3574df3d5e updated VERSION for 2.3.12 2014-04-03 07:42:39 +02:00
Fabien Potencier
aaa9a0b78a update CONTRIBUTORS for 2.3.12 2014-04-03 07:41:30 +02:00
Fabien Potencier
efbf323412 updated CHANGELOG for 2.3.12 2014-04-03 07:40:57 +02:00
Fabien Potencier
8d69022c04 Merge branch '2.4'
* 2.4:
  Revert PHPUnit version, revert APC configuration
  removed APC on the CLI for Travis as it does not work well with PHPUnit and Composer anyway
  [Security] Replace exception mocks with actual exception instances.
  Remove an unused argument.
  Use `Filesystem::chmod` instead of `chmod` when dumping file
  [Form] Added test for disabling buttons
  [Form] Added check for parent disabled status in Button form elements
  Fixes URL validator to accept single part urls
  tweaked Travis configuration to get more tests running
  fixed float comparison in unit tests for HHVM
  upgraded PHPUnit to version 4 for better HHVM support
  [Process] fixed HHVM usage on the CLI
  Fix class names in ApcUniversalClassLoader tests.
  fixed the profiler when an uncalled listener throws an exception when instantiated
  fixed CS
  Added test case for 4c6a2d15095c13b2a35751b2b2712b183be489c4
  Fixed bug in ChoiceType triggering a warning when not using utf-8
  fixed CS
  Avoid levenshtein comparison when using ContainerBuilder.
2014-04-03 07:23:57 +02:00
Fabien Potencier
785e82f814 Merge branch '2.3' into 2.4
* 2.3:
  Revert PHPUnit version, revert APC configuration
  removed APC on the CLI for Travis as it does not work well with PHPUnit and Composer anyway
  [Security] Replace exception mocks with actual exception instances.
  Remove an unused argument.
  Use `Filesystem::chmod` instead of `chmod` when dumping file
  [Form] Added test for disabling buttons
  [Form] Added check for parent disabled status in Button form elements
  Fixes URL validator to accept single part urls
  tweaked Travis configuration to get more tests running
  fixed float comparison in unit tests for HHVM
  upgraded PHPUnit to version 4 for better HHVM support
  [Process] fixed HHVM usage on the CLI
  Fix class names in ApcUniversalClassLoader tests.
  fixed the profiler when an uncalled listener throws an exception when instantiated
  fixed CS
  Added test case for 4c6a2d15095c13b2a35751b2b2712b183be489c4
  Fixed bug in ChoiceType triggering a warning when not using utf-8
  fixed CS
  Avoid levenshtein comparison when using ContainerBuilder.

Conflicts:
	src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
	src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php
2014-04-03 07:23:50 +02:00
Fabien Potencier
23709374a8 minor #10623 [2.3] Fix travis build (fabpot, romainneutron)
This PR was merged into the 2.3 branch.

Discussion
----------

[2.3] Fix travis build

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT

This PR replaces #10595 and fixes travis build on branch 2.3

Commits
-------

f613caa Revert PHPUnit version, revert APC configuration
9bdd3d1 removed APC on the CLI for Travis as it does not work well with PHPUnit and Composer anyway
2014-04-03 07:18:54 +02:00
Fabien Potencier
dfe383776a minor #10621 [Security] Replace exception mocks with actual exception instances. (jakzal)
This PR was merged into the 2.3 branch.

Discussion
----------

[Security] Replace exception mocks with actual exception instances.

It is done for two reasons:
* consistency - we use real exception objects in most of the code
* latest phpunit does not like the way we were creating mocks for exceptions (it could be also fixed by letting phpunit to call the original constructor)

Commits
-------

9438f88 [Security] Replace exception mocks with actual exception instances.
2014-04-03 07:00:33 +02:00
Romain Neutron
f613caaf5e Revert PHPUnit version, revert APC configuration 2014-04-03 00:30:22 +02:00
Fabien Potencier
9bdd3d189d removed APC on the CLI for Travis as it does not work well with PHPUnit and Composer anyway 2014-04-03 00:28:00 +02:00
Fabien Potencier
b7be0b86b9 Merge branch '2.4'
* 2.4:
  [Process] Fix Process test suite
  [Form] Fixed infinite tests when ICU is available
2014-04-02 19:10:49 +02:00
Fabien Potencier
8774a34662 minor #10620 Fix travis build (romainneutron)
This PR was merged into the 2.5-dev branch.

Discussion
----------

Fix travis build

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT

Since #10287 and #10606 have been merged, errors occur in FrameworkBundle and Console component. This patch solves this. After merging 2.4 in master (that would fix Process suite), everything should be green.

Commits
-------

099e480 Fix travis build
2014-04-02 19:10:34 +02:00
Romain Neutron
099e480c1c Fix travis build 2014-04-02 18:54:39 +02:00
Fabien Potencier
db4230ef8c feature #10619 [DependencyInjection] Use DOM instead of SimpleXML for namespace support (sandermarechal, romainneutron)
This PR was merged into the 2.5-dev branch.

Discussion
----------

[DependencyInjection] Use DOM instead of SimpleXML for namespace support

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

This PR replaces #9350

Commits
-------

a3c60c8 [DependencyInjection] Deprecate SimpleXMLElement
33c91f9 [DependencyInjection] Use DOM instead of SimpleXML for namespace support
2014-04-02 17:51:57 +02:00
Fabien Potencier
afc34cf14c feature #10606 [Console] added a better way to ask questions to the user (fabpot, romainneutron)
This PR was merged into the 2.5-dev branch.

Discussion
----------

[Console] added a better way to ask questions to the user

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | not yet

This PR replaces #9811

- [x] add missing phpdocs
- [x] add unit tests
- [ ] submit doc PR

Commits
-------

336bba2 [Console] Add docblocks and unit tests to QuestionHelper
c413f89 [Console] added a better way to ask questions to the user
2014-04-02 17:45:58 +02:00
Romain Neutron
a3c60c8039 [DependencyInjection] Deprecate SimpleXMLElement 2014-04-02 17:32:21 +02:00
Sander Marechal
33c91f9be8 [DependencyInjection] Use DOM instead of SimpleXML for namespace support 2014-04-02 17:32:21 +02:00
Romain Neutron
336bba2fd8 [Console] Add docblocks and unit tests to QuestionHelper 2014-04-02 17:11:48 +02:00
Fabien Potencier
01f21e3c31 bug #10604 [PropertyAccessor] Wrong number of parameters (coma)
This PR was merged into the 2.5-dev branch.

Discussion
----------

[PropertyAccessor] Wrong number of parameters

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

Since [6d2af217aafd03e3f1600ce0ebc9c30cf0a7fc70#diff-3e45cf556c0330623c0167841d303dff](6d2af217aa (diff-3e45cf556c0330623c0167841d303dff)) the PropertyAccessor is failing on setters with default values because  [ReflectionFunctionAbstract::getNumberOfRequiredParameters](http://www.php.net/manual/es/reflectionfunctionabstract.getnumberofparameters.php) only count the parameters without default values.

Commits
-------

6157be0 Wrong number of parameters
2014-04-01 18:23:27 +02:00
Fabien Potencier
8ced461899 feature #10600 [DependencyInjection] added a simple way to replace a service by keeping a reference to the old one (romainneutron)
This PR was merged into the 2.5-dev branch.

Discussion
----------

[DependencyInjection] added a simple way to replace a service by keeping a reference to the old one

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #5920
| License       | MIT
| Doc PR | https://github.com/symfony/symfony-docs/issues/3745

This PR replaces #9003. Here's the todo list:
 - [x] add a cookbook entry for this new feature
 - [x] add support in all loaders/dumpers
 - [x] add unit tests
 - [x] see if there are use cases in Symfony that would benefit from this new feature
 - [x] find the best name for this feature

I've implemented YAML and XML Loader / Dumper.
From what I see, PhpDumper, PhpLoader, IniLoader, GraphvizDumper do not require an update, am I wrong?

Commits
-------

140f807 [DependencyInjection] Update dumpers and loaders, add unit tests
1eb1f4d [DependencyInjection] added a simple way to replace a service by keeping a reference to the old one
2014-04-01 18:20:59 +02:00
Jakub Zalas
9438f88af0 [Security] Replace exception mocks with actual exception instances.
It is done for two reasons:
* consistency - we use real exception objects in most of the code
* latest phpunit does not like the way we were creating mocks for exceptions (it could be also fixed by letting phpunit to call the original constructor)
2014-04-01 15:48:06 +01:00
Fabien Potencier
c413f89723 [Console] added a better way to ask questions to the user 2014-04-01 14:31:41 +02:00
Eduardo García Sanz
6157be0a1d Wrong number of parameters
Wrong number of parameters

Wrong number of parameters

Wrong number of parameters
2014-04-01 14:30:09 +02:00
Romain Neutron
140f807346 [DependencyInjection] Update dumpers and loaders, add unit tests 2014-04-01 14:25:44 +02:00
Fabien Potencier
8aa194c0a6 minor #10601 [HttpKernel] HttpCache typo (jakzal)
This PR was merged into the 2.3 branch.

Discussion
----------

[HttpKernel] HttpCache typo

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

Commits
-------

8882dad Remove an unused argument.
2014-04-01 08:01:53 +02:00
Jakub Zalas
8882dad46e Remove an unused argument. 2014-03-31 22:49:46 +01:00
Fabien Potencier
1eb1f4dd73 [DependencyInjection] added a simple way to replace a service by keeping a reference to the old one 2014-03-31 20:47:44 +02:00
Fabien Potencier
58bed5d200 feature #10593 [Templating] Added ability to set a specific version of the asset (romainneutron)
This PR was merged into the 2.5-dev branch.

Discussion
----------

[Templating] Added ability to set a specific version of the asset

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT
| Doc PR        | https://github.com/symfony/symfony-docs/pull/3742/files

This PR replaces #6092

Commits
-------

1642094 [Templating] Update changelog
6fce503 [Templating] Added ability to set a specific version of the asset
2014-03-31 15:55:50 +02:00
Romain Neutron
1642094cfe [Templating] Update changelog 2014-03-31 15:27:29 +02:00
Martin Hasoň
6fce503432 [Templating] Added ability to set a specific version of the asset 2014-03-31 15:27:29 +02:00
Fabien Potencier
7792ba90db fixed typo in composer.json 2014-03-31 13:19:58 +02:00
Fabien Potencier
b094ea7fe2 bug #10586 Fixes URL validator to accept single part urls (merk)
This PR was merged into the 2.3 branch.

Discussion
----------

Fixes URL validator to accept single part urls

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #3207 #6817
| License       | MIT
| Doc PR        | N/A

This PR replaces #6817 and has been rebased for 2.3, making a change to the regex to be simpler for single dot matches. (changing `([\pL\pN\pS-\.])+([\.]{0,1}[\pL]+[\.]{0,1})` to `([\pL\pN\pS-\.])+(\.?[\pL]+\.?)`)

Commits
-------

91e226e Fixes URL validator to accept single part urls
2014-03-31 13:10:34 +02:00
Fabien Potencier
3e678e7923 minor #10590 [2.3] Use Filesystem::chmod instead of chmod when dumping file (romainneutron)
This PR was merged into the 2.3 branch.

Discussion
----------

[2.3] Use `Filesystem::chmod` instead of `chmod` when dumping file

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

This adds consistency as discussed in ca5eea5c19 (commitcomment-5804089)

Commits
-------

c2ffefd Use `Filesystem::chmod` instead of `chmod` when dumping file
2014-03-31 13:09:33 +02:00
Fabien Potencier
bd577b11a2 feature #10287 [WIP][Validator] New NodeTraverser implementation (webmozart)
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
2014-03-31 13:08:13 +02:00