Annotations
3 years ago
EntityTraits
2 years ago
EventListeners
2 months ago
Middlewares
4 weeks 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
CacheOnlyMappingDriver.php
59 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Doctrine; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\RuntimeException; |
| 9 | use MailPoetVendor\Doctrine\Persistence\Mapping\ClassMetadata; |
| 10 | use MailPoetVendor\Doctrine\Persistence\Mapping\Driver\MappingDriver; |
| 11 | use MailPoetVendor\Psr\Cache\CacheItemPoolInterface; |
| 12 | |
| 13 | /** |
| 14 | * Intended to be used in production environment where we rely on metadata cache for reading all metadata. |
| 15 | */ |
| 16 | class CacheOnlyMappingDriver implements MappingDriver { |
| 17 | /** @var string */ |
| 18 | protected $cacheSalt = '__CLASSMETADATA__'; |
| 19 | |
| 20 | /** @var CacheItemPoolInterface */ |
| 21 | private $metaDataCache; |
| 22 | |
| 23 | public function __construct( |
| 24 | CacheItemPoolInterface $metaDataCache |
| 25 | ) { |
| 26 | $this->metaDataCache = $metaDataCache; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @inerhitDoc |
| 31 | */ |
| 32 | public function loadMetadataForClass($className, ClassMetadata $metadata) { |
| 33 | // We don't need to load anything it is all cached. |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @inerhitDoc |
| 38 | */ |
| 39 | public function getAllClassNames() { |
| 40 | throw new RuntimeException('CacheOnlyMappingDriver::getAllClassNames should not be called'); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @inerhitDoc |
| 45 | */ |
| 46 | public function isTransient($className) { |
| 47 | // Everything in cache are metadata and class with metadata is non-transient |
| 48 | // See https://github.com/doctrine/persistence/blob/b07e347a24e7a19a2b6462e00a6dff899e4c2dd2/src/Persistence/Mapping/Driver/MappingDriver.php#L34 |
| 49 | return !$this->metaDataCache->hasItem($this->getCacheKey($className)); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Copy pasted from MailPoetVendor\Doctrine\Persistence\Mapping\AbstractClassMetadataFactory |
| 54 | */ |
| 55 | protected function getCacheKey(string $className): string { |
| 56 | return str_replace('\\', '__', $className) . $this->cacheSalt; |
| 57 | } |
| 58 | } |
| 59 |