DoctrineProvider.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\Cache;
  11. use Doctrine\Common\Cache\CacheProvider;
  12. use Psr\Cache\CacheItemPoolInterface;
  13. use Symfony\Contracts\Service\ResetInterface;
  14. if (!class_exists(CacheProvider::class)) {
  15. return;
  16. }
  17. /**
  18. * @author Nicolas Grekas <p@tchwork.com>
  19. *
  20. * @deprecated Use Doctrine\Common\Cache\Psr6\DoctrineProvider instead
  21. */
  22. class DoctrineProvider extends CacheProvider implements PruneableInterface, ResettableInterface
  23. {
  24. private $pool;
  25. public function __construct(CacheItemPoolInterface $pool)
  26. {
  27. trigger_deprecation('symfony/cache', '5.4', '"%s" is deprecated, use "Doctrine\Common\Cache\Psr6\DoctrineProvider" instead.', __CLASS__);
  28. $this->pool = $pool;
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function prune()
  34. {
  35. return $this->pool instanceof PruneableInterface && $this->pool->prune();
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function reset()
  41. {
  42. if ($this->pool instanceof ResetInterface) {
  43. $this->pool->reset();
  44. }
  45. $this->setNamespace($this->getNamespace());
  46. }
  47. /**
  48. * {@inheritdoc}
  49. *
  50. * @return mixed
  51. */
  52. protected function doFetch($id)
  53. {
  54. $item = $this->pool->getItem(rawurlencode($id));
  55. return $item->isHit() ? $item->get() : false;
  56. }
  57. /**
  58. * {@inheritdoc}
  59. *
  60. * @return bool
  61. */
  62. protected function doContains($id)
  63. {
  64. return $this->pool->hasItem(rawurlencode($id));
  65. }
  66. /**
  67. * {@inheritdoc}
  68. *
  69. * @return bool
  70. */
  71. protected function doSave($id, $data, $lifeTime = 0)
  72. {
  73. $item = $this->pool->getItem(rawurlencode($id));
  74. if (0 < $lifeTime) {
  75. $item->expiresAfter($lifeTime);
  76. }
  77. return $this->pool->save($item->set($data));
  78. }
  79. /**
  80. * {@inheritdoc}
  81. *
  82. * @return bool
  83. */
  84. protected function doDelete($id)
  85. {
  86. return $this->pool->deleteItem(rawurlencode($id));
  87. }
  88. /**
  89. * {@inheritdoc}
  90. *
  91. * @return bool
  92. */
  93. protected function doFlush()
  94. {
  95. return $this->pool->clear();
  96. }
  97. /**
  98. * {@inheritdoc}
  99. *
  100. * @return array|null
  101. */
  102. protected function doGetStats()
  103. {
  104. return null;
  105. }
  106. }