ParserCacheAdapter.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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\ExpressionLanguage\ParserCache;
  11. use Psr\Cache\CacheItemInterface;
  12. use Psr\Cache\CacheItemPoolInterface;
  13. use Symfony\Component\Cache\CacheItem;
  14. /**
  15. * @author Alexandre GESLIN <alexandre@gesl.in>
  16. *
  17. * @internal and will be removed in Symfony 4.0.
  18. */
  19. class ParserCacheAdapter implements CacheItemPoolInterface
  20. {
  21. private $pool;
  22. private $createCacheItem;
  23. public function __construct(ParserCacheInterface $pool)
  24. {
  25. $this->pool = $pool;
  26. $this->createCacheItem = \Closure::bind(
  27. function ($key, $value, $isHit) {
  28. $item = new CacheItem();
  29. $item->key = $key;
  30. $item->value = $value;
  31. $item->isHit = $isHit;
  32. return $item;
  33. },
  34. null,
  35. CacheItem::class
  36. );
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function getItem($key)
  42. {
  43. $value = $this->pool->fetch($key);
  44. $f = $this->createCacheItem;
  45. return $f($key, $value, null !== $value);
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function save(CacheItemInterface $item)
  51. {
  52. $this->pool->save($item->getKey(), $item->get());
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public function getItems(array $keys = [])
  58. {
  59. throw new \BadMethodCallException('Not implemented');
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function hasItem($key)
  65. {
  66. throw new \BadMethodCallException('Not implemented');
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function clear()
  72. {
  73. throw new \BadMethodCallException('Not implemented');
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function deleteItem($key)
  79. {
  80. throw new \BadMethodCallException('Not implemented');
  81. }
  82. /**
  83. * {@inheritdoc}
  84. */
  85. public function deleteItems(array $keys)
  86. {
  87. throw new \BadMethodCallException('Not implemented');
  88. }
  89. /**
  90. * {@inheritdoc}
  91. */
  92. public function saveDeferred(CacheItemInterface $item)
  93. {
  94. throw new \BadMethodCallException('Not implemented');
  95. }
  96. /**
  97. * {@inheritdoc}
  98. */
  99. public function commit()
  100. {
  101. throw new \BadMethodCallException('Not implemented');
  102. }
  103. }