[Validator] deprecated API version

This commit is contained in:
Fabien Potencier 2015-01-25 06:54:05 +01:00 committed by Christophe Coevoet
parent 0c69f6927f
commit 75088c0adc
5 changed files with 20 additions and 66 deletions

View File

@ -112,6 +112,14 @@ class Configuration implements ConfigurationInterface
return $v;
})
->end()
->beforeNormalization()
->ifTrue(function ($v) { return isset($v['validation']['api']); })
->then(function ($v) {
trigger_error('The validation.api configuration key is deprecated since version 2.7 and will be removed in 3.0', E_USER_DEPRECATED);
return $v;
})
->end()
->children()
->scalarNode('secret')->end()
->scalarNode('http_method_override')
@ -610,6 +618,7 @@ class Configuration implements ConfigurationInterface
->scalarNode('translation_domain')->defaultValue('validators')->end()
->booleanNode('strict_email')->defaultFalse()->end()
->enumNode('api')
->info('Deprecated since version 2.7, to be removed in 3.0')
->values(array('2.4', '2.5', '2.5-bc', 'auto'))
->beforeNormalization()
// XML/YAML parse as numbers, not as strings
@ -620,19 +629,6 @@ class Configuration implements ConfigurationInterface
->end()
->end()
->end()
->validate()
->ifTrue(function ($v) { return !isset($v['validation']['api']) || 'auto' === $v['validation']['api']; })
->then(function ($v) {
// This condition is duplicated in ValidatorBuilder. This
// duplication is necessary in order to know the desired
// API version already during container configuration
// (to adjust service classes etc.)
// See https://github.com/symfony/symfony/issues/11580
$v['validation']['api'] = '2.5-bc';
return $v;
})
->end()
;
}

View File

@ -761,20 +761,10 @@ class FrameworkExtension extends Extension
$validatorBuilder->addMethodCall('setMetadataCache', array(new Reference($config['cache'])));
}
if ('2.5' === $config['api']) {
$api = Validation::API_VERSION_2_5;
} else {
// 2.4 is now the same as 2.5 BC
$api = Validation::API_VERSION_2_5_BC;
// the validation class needs to be changed for BC
$container->setParameter('validator.class', 'Symfony\Component\Validator\ValidatorInterface');
}
$validatorBuilder->addMethodCall('setApiVersion', array($api));
// You can use this parameter to check the API version in your own
// bundle extension classes
$container->setParameter('validator.api', $api);
// @deprecated since version 2.7, to be removed in 3.0
$container->setParameter('validator.api', $config['api']);
}
private function getValidatorMappingFiles(ContainerBuilder $container)

View File

@ -110,31 +110,8 @@ class ValidatorBuilderTest extends \PHPUnit_Framework_TestCase
$this->assertSame($this->builder, $this->builder->setTranslationDomain('TRANS_DOMAIN'));
}
/**
* @group legacy
*/
public function testLegacyDefaultApiVersion()
public function testGetValidator()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
// Legacy compatible implementation
$this->assertInstanceOf('Symfony\Component\Validator\Validator\RecursiveValidator', $this->builder->getValidator());
}
public function testSetApiVersion25()
{
$this->assertSame($this->builder, $this->builder->setApiVersion(Validation::API_VERSION_2_5));
$this->assertInstanceOf('Symfony\Component\Validator\Validator\RecursiveValidator', $this->builder->getValidator());
}
/**
* @group legacy
*/
public function testLegacySetApiVersion24And25()
{
$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\RecursiveValidator', $this->builder->getValidator());
}
}

View File

@ -94,11 +94,6 @@ class ValidatorBuilder implements ValidatorBuilderInterface
*/
private $propertyAccessor;
/**
* @var int|null
*/
private $apiVersion;
/**
* {@inheritdoc}
*/
@ -318,17 +313,16 @@ class ValidatorBuilder implements ValidatorBuilderInterface
/**
* {@inheritdoc}
*
* @deprecated since version 2.7, to be removed in 3.0.
*/
public function setApiVersion($apiVersion)
{
if (!in_array($apiVersion, array(Validation::API_VERSION_2_4, Validation::API_VERSION_2_5, Validation::API_VERSION_2_5_BC))) {
throw new InvalidArgumentException(sprintf(
'The requested API version is invalid: "%s"',
$apiVersion
));
}
trigger_error('The '.__METHOD__.' method is deprecated in version 2.7 and will be removed in version 3.0.', E_USER_DEPRECATED);
$this->apiVersion = $apiVersion;
if (!in_array($apiVersion, array(Validation::API_VERSION_2_4, Validation::API_VERSION_2_5, Validation::API_VERSION_2_5_BC))) {
throw new InvalidArgumentException(sprintf('The requested API version is invalid: "%s"', $apiVersion));
}
return $this;
}
@ -339,11 +333,6 @@ class ValidatorBuilder implements ValidatorBuilderInterface
public function getValidator()
{
$metadataFactory = $this->metadataFactory;
$apiVersion = $this->apiVersion;
if (null === $apiVersion) {
$apiVersion = Validation::API_VERSION_2_5_BC;
}
if (!$metadataFactory) {
$loaders = array();

View File

@ -180,6 +180,8 @@ interface ValidatorBuilderInterface
*
* @see Validation::API_VERSION_2_5
* @see Validation::API_VERSION_2_5_BC
*
* @deprecated since version 2.7, to be removed in 3.0.
*/
public function setApiVersion($apiVersion);