Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 75088c0

Browse files
fabpotstof
authored andcommitted
[Validator] deprecated API version
1 parent 0c69f69 commit 75088c0

File tree

5 files changed

+19
-65
lines changed

5 files changed

+19
-65
lines changed

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ public function getConfigTreeBuilder()
112112
return $v;
113113
})
114114
->end()
115+
->beforeNormalization()
116+
->ifTrue(function ($v) { return isset($v['validation']['api']); })
117+
->then(function ($v) {
118+
trigger_error('The validation.api configuration key is deprecated since version 2.7 and will be removed in 3.0', E_USER_DEPRECATED);
119+
120+
return $v;
121+
})
122+
->end()
115123
->children()
116124
->scalarNode('secret')->end()
117125
->scalarNode('http_method_override')
@@ -610,6 +618,7 @@ private function addValidationSection(ArrayNodeDefinition $rootNode)
610618
->scalarNode('translation_domain')->defaultValue('validators')->end()
611619
->booleanNode('strict_email')->defaultFalse()->end()
612620
->enumNode('api')
621+
->info('Deprecated since version 2.7, to be removed in 3.0')
613622
->values(array('2.4', '2.5', '2.5-bc', 'auto'))
614623
->beforeNormalization()
615624
// XML/YAML parse as numbers, not as strings
@@ -620,19 +629,6 @@ private function addValidationSection(ArrayNodeDefinition $rootNode)
620629
->end()
621630
->end()
622631
->end()
623-
->validate()
624-
->ifTrue(function ($v) { return !isset($v['validation']['api']) || 'auto' === $v['validation']['api']; })
625-
->then(function ($v) {
626-
// This condition is duplicated in ValidatorBuilder. This
627-
// duplication is necessary in order to know the desired
628-
// API version already during container configuration
629-
// (to adjust service classes etc.)
630-
// See https://github.com/symfony/symfony/issues/11580
631-
$v['validation']['api'] = '2.5-bc';
632-
633-
return $v;
634-
})
635-
->end()
636632
;
637633
}
638634

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -761,20 +761,10 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
761761
$validatorBuilder->addMethodCall('setMetadataCache', array(new Reference($config['cache'])));
762762
}
763763

764-
if ('2.5' === $config['api']) {
765-
$api = Validation::API_VERSION_2_5;
766-
} else {
767-
// 2.4 is now the same as 2.5 BC
768-
$api = Validation::API_VERSION_2_5_BC;
769-
// the validation class needs to be changed for BC
770-
$container->setParameter('validator.class', 'Symfony\Component\Validator\ValidatorInterface');
771-
}
772-
773-
$validatorBuilder->addMethodCall('setApiVersion', array($api));
774-
775764
// You can use this parameter to check the API version in your own
776765
// bundle extension classes
777-
$container->setParameter('validator.api', $api);
766+
// @deprecated since version 2.7, to be removed in 3.0
767+
$container->setParameter('validator.api', $config['api']);
778768
}
779769

780770
private function getValidatorMappingFiles(ContainerBuilder $container)

src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -110,31 +110,8 @@ public function testSetTranslationDomain()
110110
$this->assertSame($this->builder, $this->builder->setTranslationDomain('TRANS_DOMAIN'));
111111
}
112112

113-
/**
114-
* @group legacy
115-
*/
116-
public function testLegacyDefaultApiVersion()
117-
{
118-
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
119-
120-
// Legacy compatible implementation
121-
$this->assertInstanceOf('Symfony\Component\Validator\Validator\RecursiveValidator', $this->builder->getValidator());
122-
}
123-
124-
public function testSetApiVersion25()
113+
public function testGetValidator()
125114
{
126-
$this->assertSame($this->builder, $this->builder->setApiVersion(Validation::API_VERSION_2_5));
127-
$this->assertInstanceOf('Symfony\Component\Validator\Validator\RecursiveValidator', $this->builder->getValidator());
128-
}
129-
130-
/**
131-
* @group legacy
132-
*/
133-
public function testLegacySetApiVersion24And25()
134-
{
135-
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
136-
137-
$this->assertSame($this->builder, $this->builder->setApiVersion(Validation::API_VERSION_2_5_BC));
138115
$this->assertInstanceOf('Symfony\Component\Validator\Validator\RecursiveValidator', $this->builder->getValidator());
139116
}
140117
}

src/Symfony/Component/Validator/ValidatorBuilder.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ class ValidatorBuilder implements ValidatorBuilderInterface
9494
*/
9595
private $propertyAccessor;
9696

97-
/**
98-
* @var int|null
99-
*/
100-
private $apiVersion;
101-
10297
/**
10398
* {@inheritdoc}
10499
*/
@@ -318,18 +313,17 @@ public function setPropertyAccessor(PropertyAccessorInterface $propertyAccessor)
318313

319314
/**
320315
* {@inheritdoc}
316+
*
317+
* @deprecated since version 2.7, to be removed in 3.0.
321318
*/
322319
public function setApiVersion($apiVersion)
323320
{
321+
trigger_error('The '.__METHOD__.' method is deprecated in version 2.7 and will be removed in version 3.0.', E_USER_DEPRECATED);
322+
324323
if (!in_array($apiVersion, array(Validation::API_VERSION_2_4, Validation::API_VERSION_2_5, Validation::API_VERSION_2_5_BC))) {
325-
throw new InvalidArgumentException(sprintf(
326-
'The requested API version is invalid: "%s"',
327-
$apiVersion
328-
));
324+
throw new InvalidArgumentException(sprintf('The requested API version is invalid: "%s"', $apiVersion));
329325
}
330326

331-
$this->apiVersion = $apiVersion;
332-
333327
return $this;
334328
}
335329

@@ -339,11 +333,6 @@ public function setApiVersion($apiVersion)
339333
public function getValidator()
340334
{
341335
$metadataFactory = $this->metadataFactory;
342-
$apiVersion = $this->apiVersion;
343-
344-
if (null === $apiVersion) {
345-
$apiVersion = Validation::API_VERSION_2_5_BC;
346-
}
347336

348337
if (!$metadataFactory) {
349338
$loaders = array();

src/Symfony/Component/Validator/ValidatorBuilderInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ public function setPropertyAccessor(PropertyAccessorInterface $propertyAccessor)
180180
*
181181
* @see Validation::API_VERSION_2_5
182182
* @see Validation::API_VERSION_2_5_BC
183+
*
184+
* @deprecated since version 2.7, to be removed in 3.0.
183185
*/
184186
public function setApiVersion($apiVersion);
185187

0 commit comments

Comments
 (0)