Updating Media dependent modules to versions compatible with core Media.
[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     private $cacheItemPool;
25
26     public function __construct(CacheItemPoolInterface $cacheItemPool)
27     {
28         $this->cacheItemPool = $cacheItemPool;
29     }
30
31     /**
32      * {@inheritdoc}
33      */
34     public function has($class)
35     {
36         return $this->cacheItemPool->hasItem($this->escapeClassName($class));
37     }
38
39     /**
40      * {@inheritdoc}
41      */
42     public function read($class)
43     {
44         $item = $this->cacheItemPool->getItem($this->escapeClassName($class));
45
46         if (!$item->isHit()) {
47             return false;
48         }
49
50         return $item->get();
51     }
52
53     /**
54      * {@inheritdoc}
55      */
56     public function write(ClassMetadata $metadata)
57     {
58         $item = $this->cacheItemPool->getItem($this->escapeClassName($metadata->getClassName()));
59         $item->set($metadata);
60
61         $this->cacheItemPool->save($item);
62     }
63
64     /**
65      * Replaces backslashes by dots in a class name.
66      *
67      * @param string $class
68      *
69      * @return string
70      */
71     private function escapeClassName($class)
72     {
73         return str_replace('\\', '.', $class);
74     }
75 }