mailpoet
/
vendor-prefixed
/
doctrine
/
cache
/
lib
/
Doctrine
/
Common
/
Cache
/
Psr6
/
DoctrineProvider.php
mailpoet
/
vendor-prefixed
/
doctrine
/
cache
/
lib
/
Doctrine
/
Common
/
Cache
/
Psr6
Last commit date
CacheAdapter.php
4 years ago
CacheItem.php
4 years ago
DoctrineProvider.php
2 years ago
InvalidArgument.php
4 years ago
TypedCacheItem.php
2 years ago
index.php
3 years ago
DoctrineProvider.php
72 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\Common\Cache\Psr6; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Doctrine\Common\Cache\Cache; |
| 5 | use MailPoetVendor\Doctrine\Common\Cache\CacheProvider; |
| 6 | use MailPoetVendor\Psr\Cache\CacheItemPoolInterface; |
| 7 | use MailPoetVendor\Symfony\Component\Cache\Adapter\DoctrineAdapter as SymfonyDoctrineAdapter; |
| 8 | use MailPoetVendor\Symfony\Contracts\Service\ResetInterface; |
| 9 | use function rawurlencode; |
| 10 | final class DoctrineProvider extends CacheProvider |
| 11 | { |
| 12 | private $pool; |
| 13 | public static function wrap(CacheItemPoolInterface $pool) : Cache |
| 14 | { |
| 15 | if ($pool instanceof CacheAdapter) { |
| 16 | return $pool->getCache(); |
| 17 | } |
| 18 | if ($pool instanceof SymfonyDoctrineAdapter) { |
| 19 | $getCache = function () { |
| 20 | // phpcs:ignore Squiz.Scope.StaticThisUsage.Found |
| 21 | return $this->provider; |
| 22 | }; |
| 23 | return $getCache->bindTo($pool, SymfonyDoctrineAdapter::class)(); |
| 24 | } |
| 25 | return new self($pool); |
| 26 | } |
| 27 | private function __construct(CacheItemPoolInterface $pool) |
| 28 | { |
| 29 | $this->pool = $pool; |
| 30 | } |
| 31 | public function getPool() : CacheItemPoolInterface |
| 32 | { |
| 33 | return $this->pool; |
| 34 | } |
| 35 | public function reset() : void |
| 36 | { |
| 37 | if ($this->pool instanceof ResetInterface) { |
| 38 | $this->pool->reset(); |
| 39 | } |
| 40 | $this->setNamespace($this->getNamespace()); |
| 41 | } |
| 42 | protected function doFetch($id) |
| 43 | { |
| 44 | $item = $this->pool->getItem(rawurlencode($id)); |
| 45 | return $item->isHit() ? $item->get() : \false; |
| 46 | } |
| 47 | protected function doContains($id) |
| 48 | { |
| 49 | return $this->pool->hasItem(rawurlencode($id)); |
| 50 | } |
| 51 | protected function doSave($id, $data, $lifeTime = 0) |
| 52 | { |
| 53 | $item = $this->pool->getItem(rawurlencode($id)); |
| 54 | if (0 < $lifeTime) { |
| 55 | $item->expiresAfter($lifeTime); |
| 56 | } |
| 57 | return $this->pool->save($item->set($data)); |
| 58 | } |
| 59 | protected function doDelete($id) |
| 60 | { |
| 61 | return $this->pool->deleteItem(rawurlencode($id)); |
| 62 | } |
| 63 | protected function doFlush() |
| 64 | { |
| 65 | return $this->pool->clear(); |
| 66 | } |
| 67 | protected function doGetStats() |
| 68 | { |
| 69 | return null; |
| 70 | } |
| 71 | } |
| 72 |