Skip to content

Commit fd23e86

Browse files
committed
Merge branch '2.5'
* 2.5: (33 commits) [Validator] Added Swedish translations [Validator] Fixed ExpressionValidator when the validation root is not an object [Validator] Fixed: Made it possible (again) to pass a class name to Validator::validatePropertyValue() Fix incorrect romanian plural translations fix axes handling in Crawler::filterXPath() fix some docblocks Fixed self-reference in 'service_container' service breaks garbage collection (and clone). [Process] Fix tests when pcntl is not available. [DependencyInjection] Roll back changes made to generated files. [Console] Roll back changes made to fixture files. Issue #11489 Added some CA and ES translations [Validator] Added more detailed inline documentation [Validator] Removed information from the violation output if the value is an array, object or resource partially reverted previous commit fixed CS Add point about ConsoleLogger to Console 2.5 changelog [Validator] Fixed failing tests [Validator] CS fixes [FrameworkBundle] Made ConstraintValidatorFactory aware of the legacy validators [Validator] Added extensive test coverage for the constraint validators for the different APIs ... Conflicts: src/Symfony/Component/Validator/Resources/translations/validators.ca.xlf
2 parents c668682 + 8f3e0fe commit fd23e86

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
741741
switch ($config['api']) {
742742
case '2.4':
743743
$api = Validation::API_VERSION_2_4;
744+
$container->setParameter('validator.validator_factory.class', $container->getParameter('validator.legacy_validator_factory.class'));
744745
break;
745746
case '2.5':
746747
$api = Validation::API_VERSION_2_5;

Resources/config/validator.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<parameter key="validator.mapping.cache.apc.class">Symfony\Component\Validator\Mapping\Cache\ApcCache</parameter>
1212
<parameter key="validator.mapping.cache.prefix" />
1313
<parameter key="validator.validator_factory.class">Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory</parameter>
14+
<parameter key="validator.legacy_validator_factory.class">Symfony\Bundle\FrameworkBundle\Validator\LegacyConstraintValidatorFactory</parameter>
1415
<parameter key="validator.expression.class">Symfony\Component\Validator\Constraints\ExpressionValidator</parameter>
1516
<parameter key="validator.email.class">Symfony\Component\Validator\Constraints\EmailValidator</parameter>
1617
</parameters>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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\Bundle\FrameworkBundle\Validator;
13+
14+
use Symfony\Component\DependencyInjection\ContainerInterface;
15+
use Symfony\Component\Validator\Constraint;
16+
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
17+
use Symfony\Component\Validator\ConstraintValidatorInterface;
18+
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
19+
20+
/**
21+
* Like {@link ConstraintValidatorFactory}, but aware of services compatible
22+
* with the 2.4 API.
23+
*
24+
* @author Bernhard Schussek <bschussek@gmail.com>
25+
* @author Kris Wallsmith <kris@symfony.com>
26+
*
27+
* @see ConstraintValidatorFactory
28+
*/
29+
class LegacyConstraintValidatorFactory implements ConstraintValidatorFactoryInterface
30+
{
31+
const BASE_NAMESPACE = 'Symfony\\Component\\Validator\\Constraints';
32+
33+
protected $container;
34+
protected $validators;
35+
36+
/**
37+
* Constructor.
38+
*
39+
* @param ContainerInterface $container The service container
40+
* @param array $validators An array of validators
41+
*/
42+
public function __construct(ContainerInterface $container, array $validators = array())
43+
{
44+
$this->container = $container;
45+
$this->validators = $validators;
46+
}
47+
48+
/**
49+
* Returns the validator for the supplied constraint.
50+
*
51+
* @param Constraint $constraint A constraint
52+
*
53+
* @return ConstraintValidatorInterface A validator for the supplied constraint
54+
*
55+
* @throws UnexpectedTypeException When the validator is not an instance of ConstraintValidatorInterface
56+
*/
57+
public function getInstance(Constraint $constraint)
58+
{
59+
$name = $constraint->validatedBy();
60+
61+
if (!isset($this->validators[$name])) {
62+
switch (get_class($constraint)) {
63+
case self::BASE_NAMESPACE.'\\All':
64+
$name = self::BASE_NAMESPACE.'\\LegacyAllValidator';
65+
break;
66+
case self::BASE_NAMESPACE.'\\Choice':
67+
$name = self::BASE_NAMESPACE.'\\LegacyChoiceValidator';
68+
break;
69+
case self::BASE_NAMESPACE.'\\Collection':
70+
$name = self::BASE_NAMESPACE.'\\LegacyCollectionValidator';
71+
break;
72+
case self::BASE_NAMESPACE.'\\Count':
73+
$name = self::BASE_NAMESPACE.'\\LegacyCountValidator';
74+
break;
75+
case self::BASE_NAMESPACE.'\\Length':
76+
$name = self::BASE_NAMESPACE.'\\LegacyLengthValidator';
77+
break;
78+
}
79+
80+
$this->validators[$name] = new $name();
81+
} elseif (is_string($this->validators[$name])) {
82+
$this->validators[$name] = $this->container->get($this->validators[$name]);
83+
}
84+
85+
if (!$this->validators[$name] instanceof ConstraintValidatorInterface) {
86+
throw new UnexpectedTypeException($this->validators[$name], 'Symfony\Component\Validator\ConstraintValidatorInterface');
87+
}
88+
89+
return $this->validators[$name];
90+
}
91+
}

0 commit comments

Comments
 (0)