8000 bug #12151 [Framework][DX] Set the proper validator class according t… · matthieuauger/symfony@d2c6c34 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit d2c6c34

Browse files
committed
bug symfony#12151 [Framework][DX] Set the proper validator class according to the configured api version (peterrehm)
This PR was submitted for the master branch but it was merged into the 2.5 branch instead (closes symfony#12151). Discussion ---------- [Framework][DX] Set the proper validator class according to the configured api version | Q | A | ------------- | --- | Bug fix? | [yes] | New feature? | [no] | BC breaks? | [no] | Deprecations? | [no] | Tests pass? | [yes] | Fixed tickets | - | License | MIT | Doc PR | - With this change the proper validator class will be dumped and therefore used for code completion in IDE's like PhpStorm which rely on the dumped container. If you have 2.4 or 2.5-bc API the class will be Symfony\Component\Validator\ValidatorInterface If you use the 2.5 API the class will be Symfony\Component\Validator\Validator\ValidatorInterface I consider this also as important for the developer experience since a wrong type hint can easily cause issues since the method signatures of the validate() method have changed. From ````php public function validate($value, $groups = null, $traverse = false, $deep = false); ```` To ````php public function validate($value, $constraints = null, $groups = null); ```` So if you want to validate specific groups you now have to pass them as the third argument instead of the second. Commits ------- eb3dd0f [Framework][DX] Set the proper validator class according to the configured api version
2 parents 643fdc8 + eb3dd0f commit d2c6c34

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,9 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
725725
break;
726726
case '2.5':
727727
$api = Validation::API_VERSION_2_5;
728+
// the validation class needs to be changed only for the 2.5 api since the deprecated interface is
729+
// set as the default interface
730+
$container->setParameter('validator.class', 'Symfony\Component\Validator\Validator\ValidatorInterface');
728731
break;
729732
default:
730733
$api = Validation::API_VERSION_2_5_BC;

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ public function testValidation2Dot4Api()
384384
$this->assertSame(array('loadValidatorMetadata'), $calls[4][1]);
385385
$this->assertSame('setApiVersion', $calls[5][0]);
386386
$this->assertSame(array(Validation::API_VERSION_2_4), $calls[5][1]);
387+
$this->assertSame('Symfony\Component\Validator\ValidatorInterface', $container->getParameter('validator.class'));
387388
// no cache, no annotations
388389
}
389390

@@ -399,6 +400,7 @@ public function testValidation2Dot5Api()
399400
$this->assertSame(array('loadValidatorMetadata'), $calls[4][1]);
400401
$this->assertSame('setApiVersion', $calls[5][0]);
401402
$this->assertSame(array(Validation::API_VERSION_2_5), $calls[5][1]);
403+
$this->assertSame('Symfony\Component\Validator\Validator\ValidatorInterface', $container->getParameter('validator.class'));
402404
// no cache, no annotations
403405
}
404406

@@ -414,6 +416,7 @@ public function testValidation2Dot5BcApi()
414416
$this->assertSame(array('loadValidatorMetadata'), $calls[4][1]);
415417
$this->assertSame('setApiVersion', $calls[5][0]);
416418
$this->assertSame(array(Validation::API_VERSION_2_5_BC), $calls[5][1]);
419+
$this->assertSame('Symfony\Component\Validator\ValidatorInterface', $container->getParameter('validator.class'));
417420
// no cache, no annotations
418421
}
419422

0 commit comments

Comments
 (0)
0