4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator\Mapping\Cache;
14 use Psr\Cache\CacheItemPoolInterface;
15 use Symfony\Component\Validator\Mapping\ClassMetadata;
20 * @author Kévin Dunglas <dunglas@gmail.com>
22 class Psr6Cache implements CacheInterface
24 private $cacheItemPool;
26 public function __construct(CacheItemPoolInterface $cacheItemPool)
28 $this->cacheItemPool = $cacheItemPool;
34 public function has($class)
36 return $this->cacheItemPool->hasItem($this->escapeClassName($class));
42 public function read($class)
44 $item = $this->cacheItemPool->getItem($this->escapeClassName($class));
46 if (!$item->isHit()) {
56 public function write(ClassMetadata $metadata)
58 $item = $this->cacheItemPool->getItem($this->escapeClassName($metadata->getClassName()));
59 $item->set($metadata);
61 $this->cacheItemPool->save($item);
65 * Replaces backslashes by dots in a class name.
67 * @param string $class
71 private function escapeClassName($class)
73 return str_replace('\\', '.', $class);