Skip to content

Commit 4ca795f

Browse files
committed
[Validator] Deprecated CacheInterface in favor of PSR-6.
1 parent a4467bd commit 4ca795f

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

CacheWarmer/ValidatorCacheWarmer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Psr\Cache\CacheItemPoolInterface;
1616
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1717
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
18-
use Symfony\Component\Validator\Mapping\Cache\Psr6Cache;
1918
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
2019
use Symfony\Component\Validator\Mapping\Loader\LoaderChain;
2120
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
@@ -59,7 +58,7 @@ protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
5958
}
6059

6160
$loaders = $this->validatorBuilder->getLoaders();
62-
$metadataFactory = new LazyLoadingMetadataFactory(new LoaderChain($loaders), new Psr6Cache($arrayAdapter));
61+
$metadataFactory = new LazyLoadingMetadataFactory(new LoaderChain($loaders), $arrayAdapter);
6362

6463
foreach ($this->extractSupportedLoaders($loaders) as $loader) {
6564
foreach ($loader->getMappedClasses() as $mappedClass) {

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
12881288
}
12891289

12901290
if (!$container->getParameter('kernel.debug')) {
1291-
$validatorBuilder->addMethodCall('setMetadataCache', [new Reference('validator.mapping.cache.symfony')]);
1291+
$validatorBuilder->addMethodCall('setMappingCache', [new Reference('validator.mapping.cache.adapter')]);
12921292
}
12931293

12941294
$container->setParameter('validator.auto_mapping', $config['auto_mapping']);

Resources/config/validator.xml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@
3939
</service>
4040

4141
<service id="validator.mapping.cache.symfony" class="Symfony\Component\Validator\Mapping\Cache\Psr6Cache">
42-
<argument type="service">
43-
<service class="Symfony\Component\Cache\Adapter\PhpArrayAdapter">
44-
<factory class="Symfony\Component\Cache\Adapter\PhpArrayAdapter" method="create" />
45-
<argument>%validator.mapping.cache.file%</argument>
46-
<argument type="service" id="cache.validator" />
47-
</service>
48-
</argument>
42+
<argument type="service" id="validator.mapping.cache.adapter" />
43+
<deprecated>The "%service_id%" service is deprecated since Symfony 4.4. Use validator.mapping.cache.adapter instead.</deprecated>
44+
</service>
45+
46+
<service id="validator.mapping.cache.adapter" class="Symfony\Component\Cache\Adapter\PhpArrayAdapter">
47+
<factory class="Symfony\Component\Cache\Adapter\PhpArrayAdapter" method="create" />
48+
<argument>%validator.mapping.cache.file%</argument>
49+
<argument type="service" id="cache.validator" />
4950
</service>
5051

5152
<service id="validator.validator_factory" class="Symfony\Component\Validator\ContainerConstraintValidatorFactory">

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,8 @@ public function testValidation()
908908
}
909909
$this->assertSame('addMethodMapping', $calls[++$i][0]);
910910
$this->assertSame(['loadValidatorMetadata'], $calls[$i][1]);
911-
$this->assertSame('setMetadataCache', $calls[++$i][0]);
912-
$this->assertEquals([new Reference('validator.mapping.cache.symfony')], $calls[$i][1]);
911+
$this->assertSame('setMappingCache', $calls[++$i][0]);
912+
$this->assertEquals([new Reference('validator.mapping.cache.adapter')], $calls[$i][1]);
913913
}
914914

915915
public function testValidationService()
@@ -951,8 +951,8 @@ public function testValidationAnnotations()
951951
$this->assertEquals([new Reference('annotation_reader')], $calls[4][1]);
952952
$this->assertSame('addMethodMapping', $calls[5][0]);
953953
$this->assertSame(['loadValidatorMetadata'], $calls[5][1]);
954-
$this->assertSame('setMetadataCache', $calls[6][0]);
955-
$this->assertEquals([new Reference('validator.mapping.cache.symfony')], $calls[6][1]);
954+
$this->assertSame('setMappingCache', $calls[6][0]);
955+
$this->assertEquals([new Reference('validator.mapping.cache.adapter')], $calls[6][1]);
956956
// no cache this time
957957
}
958958

@@ -973,8 +973,8 @@ public function testValidationPaths()
973973
$this->assertSame('enableAnnotationMapping', $calls[5][0]);
974974
$this->assertSame('addMethodMapping', $calls[6][0]);
975975
$this->assertSame(['loadValidatorMetadata'], $calls[6][1]);
976-
$this->assertSame('setMetadataCache', $calls[7][0]);
977-
$this->assertEquals([new Reference('validator.mapping.cache.symfony')], $calls[7][1]);
976+
$this->assertSame('setMappingCache', $calls[7][0]);
977+
$this->assertEquals([new Reference('validator.mapping.cache.adapter')], $calls[7][1]);
978978

979979
$xmlMappings = $calls[3][1][0];
980980
$this->assertCount(3, $xmlMappings);
@@ -1033,8 +1033,8 @@ public function testValidationNoStaticMethod()
10331033
if ($annotations) {
10341034
$this->assertSame('enableAnnotationMapping', $calls[++$i][0]);
10351035
}
1036-
$this->assertSame('setMetadataCache', $calls[++$i][0]);
1037-
$this->assertEquals([new Reference('validator.mapping.cache.symfony')], $calls[$i][1]);
1036+
$this->assertSame('setMappingCache', $calls[++$i][0]);
1037+
$this->assertEquals([new Reference('validator.mapping.cache.adapter')], $calls[$i][1]);
10381038
// no cache, no annotations, no static methods
10391039
}
10401040

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"symfony/translation": "^4.3|^5.0",
5454
"symfony/templating": "^3.4|^4.0|^5.0",
5555
"symfony/twig-bundle": "^4.4|^5.0",
56-
"symfony/validator": "^4.1|^5.0",
56+
"symfony/validator": "^4.4|^5.0",
5757
"symfony/var-dumper": "^4.3|^5.0",
5858
"symfony/workflow": "^4.3|^5.0",
5959
"symfony/yaml": "^3.4|^4.0|^5.0",
@@ -83,7 +83,7 @@
8383
"symfony/translation": "<4.3",
8484
"symfony/twig-bridge": "<4.1.1",
8585
"symfony/twig-bundle": "<4.4",
86-
"symfony/validator": "<4.1",
86+
"symfony/validator": "<4.4",
8787
"symfony/workflow": "<4.3"
8888
},
8989
"suggest": {

0 commit comments

Comments
 (0)