Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / validator / Mapping / Cache / Psr6Cache.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Validator\Mapping\Cache;
13
14 use Psr\Cache\CacheItemPoolInterface;
15 use Symfony\Component\Validator\Mapping\ClassMetadata;
16
17 /**
18  * PSR-6 adapter.
19  *
20  * @author Kévin Dunglas <dunglas@gmail.com>
21  */
22 class Psr6Cache implements CacheInterface
23 {
24     /**
25      * @var CacheItemPoolInterface
26      */
27     private $cacheItemPool;
28
29     public function __construct(CacheItemPoolInterface $cacheItemPool)
30     {
31         $this->cacheItemPool = $cacheItemPool;
32     }
33
34     /**
35      * {@inheritdoc}
36      */
37     public function has($class)
38     {
39         return $this->cacheItemPool->hasItem($this->escapeClassName($class));
40     }
41
42     /**
43      * {@inheritdoc}
44      */
45     public function read($class)
46     {
47         $item = $this->cacheItemPool->getItem($this->escapeClassName($class));
48
49         if (!$item->isHit()) {
50             return false;
51         }
52
53         return $item->get();
54     }
55
56     /**
57      * {@inheritdoc}
58      */
59     public function write(ClassMetadata $metadata)
60     {
61         $item = $this->cacheItemPool->getItem($this->escapeClassName($metadata->getClassName()));
62         $item->set($metadata);
63
64         $this->cacheItemPool->save($item);
65     }
66
67     /**
68      * Replaces backslashes by dots in a class name.
69      *
70      * @param string $class
71      *
72      * @return string
73      */
74     private function escapeClassName($class)
75     {
76         return str_replace('\\', '.', $class);
77     }
78 }