Annotations
3 years ago
EntityTraits
2 years ago
EventListeners
2 months ago
Middlewares
1 month ago
Types
2 months ago
Validator
2 months ago
WPDB
2 months ago
ArrayCache.php
2 months ago
CacheOnlyMappingDriver.php
3 years ago
ConfigurationFactory.php
3 years ago
ConnectionFactory.php
1 year ago
EntityManagerFactory.php
2 years ago
MetadataCache.php
2 months ago
PSRArrayCache.php
2 months ago
PSRCacheInvalidArgumentException.php
3 years ago
PSRCacheItem.php
2 months ago
PSRMetadataCache.php
3 years ago
ProxyClassNameResolver.php
3 years ago
Repository.php
8 months ago
TablePrefixMetadataFactory.php
6 months ago
index.php
3 years ago
PSRArrayCache.php
92 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Doctrine; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoetVendor\Psr\Cache\CacheItemInterface; |
| 9 | use MailPoetVendor\Psr\Cache\CacheItemPoolInterface; |
| 10 | |
| 11 | class PSRArrayCache implements CacheItemPoolInterface { |
| 12 | /** @var mixed[] */ |
| 13 | private $cache = []; |
| 14 | |
| 15 | /** |
| 16 | * @inheritDoc |
| 17 | */ |
| 18 | public function getItem($key) { |
| 19 | if (!is_string($key)) { |
| 20 | throw new PSRCacheInvalidArgumentException('Invalid key'); |
| 21 | } |
| 22 | if (!$this->hasItem($key)) { |
| 23 | return new PSRCacheItem($key, false); |
| 24 | } |
| 25 | return (new PSRCacheItem($key, true))->set($this->cache[$key]); |
| 26 | } |
| 27 | |
| 28 | public function getItems(array $keys = []) { |
| 29 | return array_map([$this, 'getItem'], $keys); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @inheritDoc |
| 34 | */ |
| 35 | public function hasItem($key) { |
| 36 | return array_key_exists($key, $this->cache); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @inheritDoc |
| 41 | */ |
| 42 | public function clear() { |
| 43 | $this->cache = []; |
| 44 | return true; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @inheritDoc |
| 49 | */ |
| 50 | public function deleteItem($key) { |
| 51 | if (!is_string($key)) { |
| 52 | throw new PSRCacheInvalidArgumentException('Invalid key'); |
| 53 | } |
| 54 | unset($this->cache[$key]); |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @inheritDoc |
| 60 | */ |
| 61 | public function deleteItems(array $keys) { |
| 62 | try { |
| 63 | array_map([$this, 'deleteItem'], $keys); |
| 64 | } catch (PSRCacheInvalidArgumentException $e) { |
| 65 | return false; |
| 66 | } |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @inheritDoc |
| 72 | */ |
| 73 | public function save(CacheItemInterface $item) { |
| 74 | $this->cache[$item->getKey()] = $item->get(); |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @inheritDoc |
| 80 | */ |
| 81 | public function saveDeferred(CacheItemInterface $item) { |
| 82 | return $this->save($item); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @inheritDoc |
| 87 | */ |
| 88 | public function commit() { |
| 89 | return true; |
| 90 | } |
| 91 | } |
| 92 |