Skip to content

Commit 6d09ea3

Browse files
committed
[Validator] Deprecated CacheInterface in favor of PSR-6.
1 parent 3e8a726 commit 6d09ea3

File tree

18 files changed

+139
-53
lines changed

18 files changed

+139
-53
lines changed

UPGRADE-4.4.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ Validator
296296
Set it to `true` to keep the current behavior and `false` to reject empty strings.
297297
In 5.0, it'll become optional and will default to `false`.
298298
* Overriding the methods `ConstraintValidatorTestCase::setUp()` and `ConstraintValidatorTestCase::tearDown()` without the `void` return-type is deprecated.
299+
* deprecated `Symfony\Component\Validator\Mapping\Cache\CacheInterface` and all implementations in favor of PSR-6.
300+
* deprecated `ValidatorBuilder::setMetadataCache`, use `ValidatorBuilder::setMappingCache` instead.
299301

300302
WebProfilerBundle
301303
-----------------

UPGRADE-5.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ Validator
567567
* The `symfony/expression-language` component is now required for using the `Expression` constraint
568568
* Changed the default value of `Length::$allowEmptyString` to `false` and made it optional
569569
* Added support for PHPUnit 8. A `void` return-type was added to the `ConstraintValidatorTestCase::setUp()` and `ConstraintValidatorTestCase::tearDown()` methods.
570+
* The `Symfony\Component\Validator\Mapping\Cache\CacheInterface` and all its implementations have been removed.
571+
* The `ValidatorBuilder::setMetadataCache` has been removed, use `ValidatorBuilder::setMappingCache` instead.
570572

571573
WebProfilerBundle
572574
-----------------

src/Symfony/Bundle/FrameworkBundle/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) {

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

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

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

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

src/Symfony/Bundle/FrameworkBundle/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 and will be removed in 5.0.</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">

src/Symfony/Bundle/FrameworkBundle/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

src/Symfony/Bundle/FrameworkBundle/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": {

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ CHANGELOG
2222
be used in the violation builder when both `min` and `max` are not null
2323
* added ability to use stringable objects as violation messages
2424
* Overriding the methods `ConstraintValidatorTestCase::setUp()` and `ConstraintValidatorTestCase::tearDown()` without the `void` return-type is deprecated.
25+
* deprecated `Symfony\Component\Validator\Mapping\Cache\CacheInterface` in favor of PSR-6.
26+
* deprecated `ValidatorBuilder::setMetadataCache`, use `ValidatorBuilder::setMappingCache` instead.
2527

2628
4.3.0
2729
-----

src/Symfony/Component/Validator/Mapping/Cache/CacheInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* Persists ClassMetadata instances in a cache.
1818
*
1919
* @author Bernhard Schussek <bschussek@gmail.com>
20+
*
21+
* @deprecated in Symfony 4.4, will be removed in 5.0.
2022
*/
2123
interface CacheInterface
2224
{

src/Symfony/Component/Validator/Mapping/Cache/DoctrineCache.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
use Doctrine\Common\Cache\Cache;
1515
use Symfony\Component\Validator\Mapping\ClassMetadata;
1616

17+
@trigger_error(sprintf('%s is deprecated in Symfony 4.4 and will be removed in 5.0', DoctrineCache::class), E_USER_DEPRECATED);
18+
1719
/**
1820
* Adapts a Doctrine cache to a CacheInterface.
1921
*
2022
* @author Florian Voutzinos <florian@voutzinos.com>
23+
*
24+
* @deprecated in Symfony 4.4, will be removed in 5.0.
2125
*/
2226
final class DoctrineCache implements CacheInterface
2327
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy