Skip to content

Commit 35d7285

Browse files
committed
[Validator] Removed CacheInterface in favor of PSR-6.
1 parent 9623003 commit 35d7285

File tree

11 files changed

+8
-478
lines changed

11 files changed

+8
-478
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml

-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838
<tag name="kernel.cache_warmer" />
3939
</service>
4040

41-
<service id="validator.mapping.cache.symfony" class="Symfony\Component\Validator\Mapping\Cache\Psr6Cache">
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-
4641
<service id="validator.mapping.cache.adapter" class="Symfony\Component\Cache\Adapter\PhpArrayAdapter">
4742
<factory class="Symfony\Component\Cache\Adapter\PhpArrayAdapter" method="create" />
4843
<argument>%validator.mapping.cache.file%</argument>

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

-45
This file was deleted.

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

-63
This file was deleted.

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

-80
This file was deleted.

src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php

+8-33
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Psr\Cache\CacheItemPoolInterface;
1515
use Symfony\Component\Validator\Exception\NoSuchMetadataException;
16-
use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
1716
use Symfony\Component\Validator\Mapping\ClassMetadata;
1817
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
1918

@@ -49,20 +48,8 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
4948
*/
5049
protected $loadedClasses = [];
5150

52-
/**
53-
* Creates a new metadata factory.
54-
*
55-
* @param CacheItemPoolInterface|null $cache The cache for persisting metadata
56-
* between multiple PHP requests
57-
*/
58-
public function __construct(LoaderInterface $loader = null, $cache = null)
51+
public function __construct(LoaderInterface $loader = null, CacheItemPoolInterface $cache = null)
5952
{
60-
if ($cache instanceof CacheInterface) {
61-
@trigger_error(sprintf('Passing a "%s" to "%s" is deprecated in Symfony 4.4 and will trigger a TypeError in 5.0. Please pass an implementation of "%s" instead.', \get_class($cache), __METHOD__, CacheItemPoolInterface::class), E_USER_DEPRECATED);
62-
} elseif (!$cache instanceof CacheItemPoolInterface && null !== $cache) {
63-
throw new \TypeError(sprintf('Expected an instance of %s, got %s.', CacheItemPoolInterface::class, \is_object($cache) ? \get_class($cache) : \gettype($cache)));
64-
}
65-
6653
$this->loader = $loader;
6754
$this->cache = $cache;
6855
}
@@ -98,24 +85,14 @@ public function getMetadataFor($value)
9885
throw new NoSuchMetadataException(sprintf('The class or interface "%s" does not exist.', $class));
9986
}
10087

101-
$cacheItem = null;
102-
if ($this->cache instanceof CacheInterface) {
103-
if ($metadata = $this->cache->read($class)) {
104-
// Include constraints from the parent class
105-
$this->mergeConstraints($metadata);
106-
107-
return $this->loadedClasses[$class] = $metadata;
108-
}
109-
} elseif (null !== $this->cache) {
110-
$cacheItem = $this->cache->getItem($this->escapeClassName($class));
111-
if ($cacheItem->isHit()) {
112-
$metadata = $cacheItem->get();
88+
$cacheItem = null === $this->cache ? null : $this->cache->getItem($this->escapeClassName($class));
89+
if ($cacheItem && $cacheItem->isHit()) {
90+
$metadata = $cacheItem->get();
11391

114-
// Include constraints from the parent class
115-
$this->mergeConstraints($metadata);
92+
// Include constraints from the parent class
93+
$this->mergeConstraints($metadata);
11694

117-
return $this->loadedClasses[$class] = $metadata;
118-
}
95+
return $this->loadedClasses[$class] = $metadata;
11996
}
12097

12198
$metadata = new ClassMetadata($class);
@@ -124,9 +101,7 @@ public function getMetadataFor($value)
124101
$this->loader->loadClassMetadata($metadata);
125102
}
126103

127-
if ($this->cache instanceof CacheInterface) {
128-
$this->cache->write($metadata);
129-
} elseif (null !== $cacheItem) {
104+
if (null !== $cacheItem) {
130105
$this->cache->save($cacheItem->set($metadata));
131106
}
132107

src/Symfony/Component/Validator/Tests/Mapping/Cache/AbstractCacheTest.php

-79
This file was deleted.

src/Symfony/Component/Validator/Tests/Mapping/Cache/DoctrineCacheTest.php

-26
This file was deleted.

0 commit comments

Comments
 (0)