6dd5447fedc88a98d44b935ac99ee278bc4464cd
[yaffs-website] / vendor / symfony / validator / Mapping / Cache / DoctrineCache.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 Doctrine\Common\Cache\Cache;
15 use Symfony\Component\Validator\Mapping\ClassMetadata;
16
17 /**
18  * Adapts a Doctrine cache to a CacheInterface.
19  *
20  * @author Florian Voutzinos <florian@voutzinos.com>
21  */
22 final class DoctrineCache implements CacheInterface
23 {
24     private $cache;
25
26     /**
27      * Creates a new Doctrine cache.
28      *
29      * @param Cache $cache The cache to adapt
30      */
31     public function __construct(Cache $cache)
32     {
33         $this->cache = $cache;
34     }
35
36     /**
37      * Sets the cache to adapt.
38      *
39      * @param Cache $cache The cache to adapt
40      */
41     public function setCache(Cache $cache)
42     {
43         $this->cache = $cache;
44     }
45
46     /**
47      * {@inheritdoc}
48      */
49     public function has($class)
50     {
51         return $this->cache->contains($class);
52     }
53
54     /**
55      * {@inheritdoc}
56      */
57     public function read($class)
58     {
59         return $this->cache->fetch($class);
60     }
61
62     /**
63      * {@inheritdoc}
64      */
65     public function write(ClassMetadata $metadata)
66     {
67         $this->cache->save($metadata->getClassName(), $metadata);
68     }
69 }