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