Removed 2.5 bc layer
This commit is contained in:
parent
d1131dbf93
commit
0c69f6927f
@ -306,14 +306,14 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
|
||||
$container = $this->createContainerFromFile('full');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Validator\ValidatorInterface', $container->get('validator'));
|
||||
$this->assertInstanceOf('Symfony\Component\Validator\Validator\ValidatorInterface', $container->get('validator'));
|
||||
}
|
||||
|
||||
public function testValidationService()
|
||||
{
|
||||
$container = $this->createContainerFromFile('validation_annotations');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Validator\ValidatorInterface', $container->get('validator'));
|
||||
$this->assertInstanceOf('Symfony\Component\Validator\Validator\ValidatorInterface', $container->get('validator'));
|
||||
}
|
||||
|
||||
public function testAnnotations()
|
||||
|
@ -118,7 +118,7 @@ class ValidatorBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
|
||||
// Legacy compatible implementation
|
||||
$this->assertInstanceOf('Symfony\Component\Validator\Validator\LegacyValidator', $this->builder->getValidator());
|
||||
$this->assertInstanceOf('Symfony\Component\Validator\Validator\RecursiveValidator', $this->builder->getValidator());
|
||||
}
|
||||
|
||||
public function testSetApiVersion25()
|
||||
@ -135,6 +135,6 @@ class ValidatorBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
|
||||
$this->assertSame($this->builder, $this->builder->setApiVersion(Validation::API_VERSION_2_5_BC));
|
||||
$this->assertInstanceOf('Symfony\Component\Validator\Validator\LegacyValidator', $this->builder->getValidator());
|
||||
$this->assertInstanceOf('Symfony\Component\Validator\Validator\RecursiveValidator', $this->builder->getValidator());
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Validator;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Constraints\GroupSequence;
|
||||
use Symfony\Component\Validator\Constraints\Valid;
|
||||
use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface;
|
||||
|
||||
/**
|
||||
@ -31,22 +28,9 @@ class LegacyValidator extends RecursiveValidator implements LegacyValidatorInter
|
||||
{
|
||||
public function validate($value, $groups = null, $traverse = false, $deep = false)
|
||||
{
|
||||
$numArgs = func_num_args();
|
||||
|
||||
// Use new signature if constraints are given in the second argument
|
||||
if (self::testConstraints($groups) && ($numArgs < 3 || 3 === $numArgs && self::testGroups($traverse))) {
|
||||
// Rename to avoid total confusion ;)
|
||||
$constraints = $groups;
|
||||
$groups = $traverse;
|
||||
|
||||
return parent::validate($value, $constraints, $groups);
|
||||
}
|
||||
|
||||
trigger_error('The '.__METHOD__.' method is deprecated in version 2.5 and will be removed in version 3.0. Use the Symfony\Component\Validator\Validator\ValidatorInterface::validate method instead.', E_USER_DEPRECATED);
|
||||
|
||||
$constraint = new Valid(array('traverse' => $traverse, 'deep' => $deep));
|
||||
|
||||
return parent::validate($value, $constraint, $groups);
|
||||
return parent::validate($value, false, $groups, $traverse, $deep);
|
||||
}
|
||||
|
||||
public function validateValue($value, $constraints, $groups = null)
|
||||
@ -62,14 +46,4 @@ class LegacyValidator extends RecursiveValidator implements LegacyValidatorInter
|
||||
|
||||
return $this->metadataFactory;
|
||||
}
|
||||
|
||||
private static function testConstraints($constraints)
|
||||
{
|
||||
return null === $constraints || $constraints instanceof Constraint || (is_array($constraints) && current($constraints) instanceof Constraint);
|
||||
}
|
||||
|
||||
private static function testGroups($groups)
|
||||
{
|
||||
return null === $groups || is_string($groups) || $groups instanceof GroupSequence || (is_array($groups) && (is_string(current($groups)) || current($groups) instanceof GroupSequence));
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Validator;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Constraints\GroupSequence;
|
||||
use Symfony\Component\Validator\Constraints\Valid;
|
||||
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextFactoryInterface;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
@ -112,6 +115,22 @@ class RecursiveValidator implements ValidatorInterface
|
||||
*/
|
||||
public function validate($value, $constraints = null, $groups = null)
|
||||
{
|
||||
// The following code must be removed in 3.0
|
||||
$numArgs = func_num_args();
|
||||
if ($numArgs > 3) {
|
||||
trigger_error('The '.__METHOD__.' method is deprecated in version 2.5 and will be removed in version 3.0. Use the Symfony\Component\Validator\Validator\ValidatorInterface::validate method instead.', E_USER_DEPRECATED);
|
||||
$traverse = func_get_arg(3);
|
||||
$deep = func_get_arg(4);
|
||||
$constraints = new Valid(array('traverse' => $traverse, 'deep' => $deep));
|
||||
|
||||
if (self::testConstraints($groups)) {
|
||||
if ((!$traverse && !$deep) || self::testGroups($traverse)) {
|
||||
$constraints = $groups;
|
||||
$groups = $traverse;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->startContext($value)
|
||||
->validate($value, $constraints, $groups)
|
||||
->getViolations();
|
||||
@ -137,4 +156,22 @@ class RecursiveValidator implements ValidatorInterface
|
||||
->validatePropertyValue($objectOrClass, $propertyName, $value, $groups)
|
||||
->getViolations();
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated since version 2.5, to be removed in 3.0.
|
||||
*/
|
||||
private static function testConstraints($constraints)
|
||||
{
|
||||
return null === $constraints || $constraints instanceof Constraint || (is_array($constraints) && current($constraints) instanceof Constraint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated since version 2.5, to be removed in 3.0.
|
||||
*/
|
||||
private static function testGroups($groups)
|
||||
{
|
||||
return null === $groups || is_string($groups) || $groups instanceof GroupSequence || (is_array($groups) && (is_string(current($groups)) || current($groups) instanceof GroupSequence));
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
||||
use Symfony\Component\Translation\IdentityTranslator;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextFactory;
|
||||
use Symfony\Component\Validator\Context\LegacyExecutionContextFactory;
|
||||
use Symfony\Component\Validator\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||
use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
|
||||
@ -31,7 +30,6 @@ use Symfony\Component\Validator\Mapping\Loader\XmlFileLoader;
|
||||
use Symfony\Component\Validator\Mapping\Loader\XmlFilesLoader;
|
||||
use Symfony\Component\Validator\Mapping\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Validator\Mapping\Loader\YamlFilesLoader;
|
||||
use Symfony\Component\Validator\Validator\LegacyValidator;
|
||||
use Symfony\Component\Validator\Validator\RecursiveValidator;
|
||||
|
||||
/**
|
||||
@ -393,14 +391,8 @@ class ValidatorBuilder implements ValidatorBuilderInterface
|
||||
$translator->setLocale('en');
|
||||
}
|
||||
|
||||
if (Validation::API_VERSION_2_5 === $apiVersion) {
|
||||
$contextFactory = new ExecutionContextFactory($translator, $this->translationDomain);
|
||||
$contextFactory = new ExecutionContextFactory($translator, $this->translationDomain);
|
||||
|
||||
return new RecursiveValidator($contextFactory, $metadataFactory, $validatorFactory, $this->initializers);
|
||||
}
|
||||
|
||||
$contextFactory = new LegacyExecutionContextFactory($metadataFactory, $translator, $this->translationDomain);
|
||||
|
||||
return new LegacyValidator($contextFactory, $metadataFactory, $validatorFactory, $this->initializers);
|
||||
return new RecursiveValidator($contextFactory, $metadataFactory, $validatorFactory, $this->initializers);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user