DoctrineParserCache.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\Bridge\Doctrine\ExpressionLanguage;
  11. use Doctrine\Common\Cache\Cache;
  12. use Symfony\Component\ExpressionLanguage\ParsedExpression;
  13. use Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface;
  14. /**
  15. * @author Adrien Brault <adrien.brault@gmail.com>
  16. */
  17. class DoctrineParserCache implements ParserCacheInterface
  18. {
  19. private $cache;
  20. public function __construct(Cache $cache)
  21. {
  22. $this->cache = $cache;
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function fetch($key)
  28. {
  29. if (false === $value = $this->cache->fetch($key)) {
  30. return;
  31. }
  32. return $value;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function save($key, ParsedExpression $expression)
  38. {
  39. $this->cache->save($key, $expression);
  40. }
  41. }