DoctrineCache.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Validator\Mapping\Cache;
  11. use Doctrine\Common\Cache\Cache;
  12. use Symfony\Component\Validator\Mapping\ClassMetadata;
  13. /**
  14. * Adapts a Doctrine cache to a CacheInterface.
  15. *
  16. * @author Florian Voutzinos <florian@voutzinos.com>
  17. */
  18. final class DoctrineCache implements CacheInterface
  19. {
  20. private $cache;
  21. public function __construct(Cache $cache)
  22. {
  23. $this->cache = $cache;
  24. }
  25. public function setCache(Cache $cache)
  26. {
  27. $this->cache = $cache;
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function has($class)
  33. {
  34. return $this->cache->contains($class);
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function read($class)
  40. {
  41. return $this->cache->fetch($class);
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function write(ClassMetadata $metadata)
  47. {
  48. $this->cache->save($metadata->getClassName(), $metadata);
  49. }
  50. }