Drupal investigation

DoctrineCache.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. /**
  22. * Creates a new Doctrine cache.
  23. *
  24. * @param Cache $cache The cache to adapt
  25. */
  26. public function __construct(Cache $cache)
  27. {
  28. $this->cache = $cache;
  29. }
  30. /**
  31. * Sets the cache to adapt.
  32. *
  33. * @param Cache $cache The cache to adapt
  34. */
  35. public function setCache(Cache $cache)
  36. {
  37. $this->cache = $cache;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function has($class)
  43. {
  44. return $this->cache->contains($class);
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function read($class)
  50. {
  51. return $this->cache->fetch($class);
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function write(ClassMetadata $metadata)
  57. {
  58. $this->cache->save($metadata->getClassName(), $metadata);
  59. }
  60. }