8000 Merge branch '3.3' into 3.4 · symfony/symfony@dd617b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit dd617b3

Browse files
Merge branch '3.3' into 3.4
* 3.3: fixed CS Only override getProjectDir if it exists in the kernel [FrameworkBundle][Validator] Move the PSR-11 factory to the component
2 parents e9f0e84 + 4e8f403 commit dd617b3

File tree

11 files changed

+194
-57
lines changed

11 files changed

+194
-57
lines changed

UPGRADE-3.3.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,6 @@ FrameworkBundle
203203
deprecated and will be removed in 4.0. Use the `Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass`
204204
class instead.
205205

206-
* The `ConstraintValidatorFactory::$validators` and `$container` properties
207-
have been deprecated and will be removed in 4.0.
208-
209-
* Extending `ConstraintValidatorFactory` is deprecated and won't be supported in 4.0.
210-
211206
* Class parameters related to routing have been deprecated and will be removed in 4.0.
212207
* router.options.generator_class
213208
* router.options.generator_base_class
@@ -246,9 +241,9 @@ FrameworkBundle
246241
class has been deprecated and will be removed in 4.0. Use the
247242
`Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass` class instead.
248243

249-
* Passing an array of validators or validator aliases as the second argument of
250-
`ConstraintValidatorFactory::__construct()` is deprecated since 3.3 and will
251-
be removed in 4.0. Use the service locator instead.
244+
* The `Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory`
245+
class has been deprecated and will be removed in 4.0.
246+
Use `Symfony\Component\Validator\ContainerConstraintValidatorFactory` instead.
252247

253248
HttpFoundation
254249
--------------

UPGRADE-4.0.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,6 @@ FrameworkBundle
298298
removed. Use the `Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass`
299299
class instead.
300300

301-
* The `ConstraintValidatorFactory::$validators` and `$container` properties
302-
have been removed.
303-
304-
* Extending `ConstraintValidatorFactory` is not supported anymore.
305-
306-
* Passing an array of validators or validator aliases as the second argument of
307-
`ConstraintValidatorFactory::__construct()` has been removed.
308-
Use the service locator instead.
309-
310301
* Class parameters related to routing have been removed
311302
* router.options.generator_class
312303
* router.options.generator_base_class
@@ -340,6 +331,9 @@ FrameworkBundle
340331
has been removed. Use the `Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass`
341332
class instead.
342333

334+
* The `Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory` class has been removed.
335+
Use `Symfony\Component\Validator\ContainerConstraintValidatorFactory` instead.
336+
343337
HttpFoundation
344338
--------------
345339

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ CHANGELOG
3131
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass`.
3232
Use `Symfony\Component\Console\DependencyInjection\ConfigCachePass` instead.
3333
* Deprecated `PropertyInfoPass`, use `Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass` instead
34-
* Deprecated extending `ConstraintValidatorFactory`
3534
* Deprecated `ControllerArgumentValueResolverPass`. Use
3635
`Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass` instead
3736
* Deprecated `RoutingResolverPass`, use `Symfony\Component\Routing\DependencyInjection\RoutingResolverPass` instead
@@ -47,9 +46,10 @@ CHANGELOG
4746
`Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass` instead
4847
* Deprecated `AddConstraintValidatorsPass`, use
4948
`Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass` instead
50-
* Deprecated `ValidateWorkflowsPass`, use
49+
* Deprecated `ValidateWorkflowsPass`, use
5150
`Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass` instead
52-
* Deprecated `ConstraintValidatorFactory::__construct()` second argument.
51+
* Deprecated `ConstraintValidatorFactory`, use
52+
`Symfony\Component\Validator\ContainerConstraintValidatorFactory` instead.
5353

5454
3.2.0
5555
-----

src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,27 @@ protected function warmup($warmupDir, $realCacheDir, $enableOptionalWarmers = tr
199199
*/
200200
protected function getTempKernel(KernelInterface $parent, $namespace, $parentClass, $warmupDir)
201201
{
202+
$projectDir = '';
202203
$cacheDir = var_export($warmupDir, true);
203204
$rootDir = var_export(realpath($parent->getRootDir()), true);
204-
$projectDir = var_export(realpath($parent->getProjectDir()), true);
205205
$logDir = var_export(realpath($parent->getLogDir()), true);
206206
// the temp kernel class name must have the same length than the real one
207207
// to avoid the many problems in serialized resources files
208208
$class = substr($parentClass, 0, -1).'_';
209209
// the temp container class must be changed too
210210
$containerClass = var_export(substr(get_class($parent->getContainer()), 0, -1).'_', true);
211+
212+
if (method_exists($parent, 'getProjectDir')) {
213+
$projectDir = var_export(realpath($parent->getProjectDir()), true);
214+
$projectDir = <<<EOF
215+
public function getProjectDir()
216+
{
217+
return $projectDir;
218+
}
219+
220+
EOF;
221+
}
222+
211223
$code = <<<EOF
212224
<?php
213225
@@ -225,11 +237,7 @@ public function getRootDir()
225237
return $rootDir;
226238
}
227239
228-
public function getProjectDir()
229-
{
230-
return $projectDir;
231-
}
232-
240+
$projectDir
233241
public function getLogDir()
234242
{
235243
return $logDir;

src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
</argument>
6060
</service>
6161

62-
<service id="validator.validator_factory" class="Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory">
62+
<service id="validator.validator_factory" class="Symfony\Component\Validator\ContainerConstraintValidatorFactory">
6363
<argument /> <!-- Constraint validators locator -->
6464
</service>
6565

src/Symfony/Bundle/FrameworkBundle/Tests/Validator/ConstraintValidatorFactoryTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
use Symfony\Component\Validator\Constraints\Blank as BlankConstraint;
2020
use Symfony\Component\Validator\ConstraintValidator;
2121

22+
/**
23+
* @group legacy
24+
*/
2225
class ConstraintValidatorFactoryTest extends TestCase
2326
{
2427
public function testGetInstanceCreatesValidator()
@@ -27,7 +30,7 @@ public function testGetInstanceCreatesValidator()
2730

2831
$constraint = $this->getMockBuilder('Symfony\\Component\\Validator\\Constraint')->getMock();
2932
$constraint
30-
->expects($this->once())
33+
->expects($this->exactly(2))
3134
->method('validatedBy')
3235
->will($this->returnValue($class));
3336

@@ -63,18 +66,14 @@ public function testGetInstanceReturnsService()
6366

6467
$constraint = $this->getMockBuilder(Constraint::class)->getMock();
6568
$constraint
66-
->expects($this->once())
69+
->expects($this->exactly(2))
6770
->method('validatedBy')
6871
->will($this->returnValue($service));
6972

7073
$factory = new ConstraintValidatorFactory($container);
7174
$this->assertSame($validator, $factory->getInstance($constraint));
7275
}
7376

74-
/**
75-
* @group legacy
76-
* @expectedDeprecation Passing an array of validators or validator aliases as the second argument of "Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory::__construct" is deprecated since 3.3 and will be removed in 4.0. Use the service locator instead.
77-
*/
7877
public function testGetInstanceReturnsServiceWithAlias()
7978
{
8079
$service = 'validator_constraint_service';
@@ -106,7 +105,7 @@ public function testGetInstanceInvalidValidatorClass()
106105
{
107106
$constraint = $this->getMockBuilder('Symfony\\Component\\Validator\\Constraint')->getMock();
108107
$constraint
109-
->expects($this->once())
108+
->expects($this->exactly(2))
110109
->method('validatedBy')
111110
->will($this->returnValue('Fully\\Qualified\\ConstraintValidator\\Class\\Name'));
112111

src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313

1414
use Psr\Container\ContainerInterface;
1515
use Symfony\Component\Validator\Constraint;
16-
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
1716
use Symfony\Component\Validator\ConstraintValidatorInterface;
18-
use Symfony\Component\Validator\Exception\ValidatorException;
17+
use Symfony\Component\Validator\ContainerConstraintValidatorFactory;
1918
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
19+
use Symfony\Component\Validator\Exception\ValidatorException;
20+
21+
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use %s instead.', ConstraintValidatorFactory::class, ContainerConstraintValidatorFactory::class), E_USER_DEPRECATED);
2022

2123
/**
2224
* Uses a service container to create constraint validators.
@@ -38,24 +40,19 @@
3840
*
3941
* @author Kris Wallsmith <kris@symfony.com>
4042
*
41-
* @final since version 3.3
43+
* @deprecated since version 3.3
4244
*/
43-
class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface
45+
class ConstraintValidatorFactory extends ContainerConstraintValidatorFactory
4446
{
4547
protected $container;
4648
protected $validators;
4749

48-
public function __construct(ContainerInterface $container, array $validators = null)
50+
public function __construct(ContainerInterface $container, array $validators = array())
4951
{
50-
$this->container = $container;
51-
52-
if (null !== $validators) {
53-
@trigger_error(sprintf('Passing an array of validators or validator aliases as the second argument of "%s" is deprecated since 3.3 and will be removed in 4.0. Use the service locator instead.', __METHOD__), E_USER_DEPRECATED);
54-
} else {
55-
$validators = array();
56-
}
52+
parent::__construct($container);
5753

5854
$this->validators = $validators;
55+
$this->container = $container;
5956
}
6057

6158
/**
@@ -73,17 +70,10 @@ public function getInstance(Constraint $constraint)
7370
$name = $constraint->validatedBy();
7471

7572
if (!isset($this->validators[$name])) {
76-
if ($this->container->has($name)) {
77-
$this->validators[$name] = $this->container->get($name);
78-
} else {
79-
if (!class_exists($name)) {
80-
throw new ValidatorException(sprintf('Constraint validator "%s" does not exist or it is not enabled. Check the "validatedBy" method in your constraint class "%s".', $name, get_class($constraint)));
81-
}
73+
return parent::getInstance($constraint);
74+
}
8275

83-
$this->validators[$name] = new $name();
84-
}
85-
} elseif (is_string($this->validators[$name])) {
86-
// To be removed in 4.0
76+
if (is_string($this->validators[$name])) {
8777
$this->validators[$name] = $this->container->get($this->validators[$name]);
8878
}
8979

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"symfony/property-info": "<3.3",
7070
"symfony/serializer": "<3.3",
7171
"symfony/translation": "<3.2",
72-
"symfony/validator": "<3.3",
72+
"symfony/validator": "<3.3-rc2",
7373
"symfony/workflow": "<3.3"
7474
},
7575
"suggest": {

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CHANGELOG
1212

1313
* added `AddValidatorInitializersPass`
1414
* added `AddConstraintValidatorsPass`
15+
* added `ContainerConstraintValidatorFactory`
1516

1617
3.2.0
1718
-----
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator;
13+
14+
use Psr\Container\ContainerInterface;
15+
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
16+
use Symfony\Component\Validator\Exception\ValidatorException;
17+
18+
/**
19+
* Uses a service container to create constraint validators.
20+
*
21+
* @author Kris Wallsmith <kris@symfony.com>
22+
*/
23+
class ContainerConstraintValidatorFactory implements ConstraintValidatorFactoryInterface
24+
{
25+
private $container;
26+
private $validators;
27+
28+
public function __construct(ContainerInterface $container)
29+
{
30+
$this->container = $container;
31+
$this->validators = array();
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*
37+
* @throws ValidatorException When the validator class does not exist
38+
* @throws UnexpectedTypeException When the validator is not an instance of ConstraintValidatorInterface
39+
*/
40+
public function getInstance(Constraint $constraint)
41+
{
42+
$name = $constraint->validatedBy();
43+
44+
if (!isset($this->validators[$name])) {
45+
if ($this->container->has($name)) {
46+
$this->validators[$name] = $this->container->get($name);
47+
} else {
48+
if (!class_exists($name)) {
49+
throw new ValidatorException(sprintf('Constraint validator "%s" does not exist or it is not enabled. Check the "validatedBy" method in your constraint class "%s".', $name, get_class($constraint)));
50+
}
51+
52+
$this->validators[$name] = new $name();
53+
}
54+
}
55+
56+
if (!$this->validators[$name] instanceof ConstraintValidatorInterface) {
57+
throw new UnexpectedTypeException($this->validators[$name], ConstraintValidatorInterface::class);
58+
}
59+
60+
return $this->validators[$name];
61+
}
62+
}

0 commit comments

Comments
 (0)
0