Exception
9 months ago
Logging
9 months ago
Persister
9 months ago
Region
9 months ago
AssociationCacheEntry.php
9 months ago
CacheConfiguration.php
9 months ago
CacheEntry.php
9 months ago
CacheException.php
9 months ago
CacheFactory.php
9 months ago
CacheKey.php
9 months ago
CollectionCacheEntry.php
9 months ago
CollectionCacheKey.php
9 months ago
CollectionHydrator.php
9 months ago
ConcurrentRegion.php
9 months ago
DefaultCache.php
9 months ago
DefaultCacheFactory.php
9 months ago
DefaultCollectionHydrator.php
9 months ago
DefaultEntityHydrator.php
9 months ago
DefaultQueryCache.php
9 months ago
EntityCacheEntry.php
9 months ago
EntityCacheKey.php
9 months ago
EntityHydrator.php
9 months ago
Lock.php
9 months ago
LockException.php
9 months ago
MultiGetRegion.php
9 months ago
QueryCache.php
9 months ago
QueryCacheEntry.php
9 months ago
QueryCacheKey.php
9 months ago
QueryCacheValidator.php
9 months ago
Region.php
9 months ago
RegionsConfiguration.php
9 months ago
TimestampCacheEntry.php
9 months ago
TimestampCacheKey.php
9 months ago
TimestampQueryCacheValidator.php
9 months ago
TimestampRegion.php
9 months ago
index.php
9 months ago
DefaultCollectionHydrator.php
50 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM\Cache; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\ORM\Cache\Persister\CachedPersister; |
| 6 | use MailPoetVendor\Doctrine\ORM\EntityManagerInterface; |
| 7 | use MailPoetVendor\Doctrine\ORM\Mapping\ClassMetadata; |
| 8 | use MailPoetVendor\Doctrine\ORM\PersistentCollection; |
| 9 | use MailPoetVendor\Doctrine\ORM\Query; |
| 10 | use MailPoetVendor\Doctrine\ORM\UnitOfWork; |
| 11 | use function assert; |
| 12 | class DefaultCollectionHydrator implements CollectionHydrator |
| 13 | { |
| 14 | private $em; |
| 15 | private $uow; |
| 16 | private static $hints = [Query::HINT_CACHE_ENABLED => \true]; |
| 17 | public function __construct(EntityManagerInterface $em) |
| 18 | { |
| 19 | $this->em = $em; |
| 20 | $this->uow = $em->getUnitOfWork(); |
| 21 | } |
| 22 | public function buildCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, $collection) |
| 23 | { |
| 24 | $data = []; |
| 25 | foreach ($collection as $index => $entity) { |
| 26 | $data[$index] = new EntityCacheKey($metadata->rootEntityName, $this->uow->getEntityIdentifier($entity)); |
| 27 | } |
| 28 | return new CollectionCacheEntry($data); |
| 29 | } |
| 30 | public function loadCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, CollectionCacheEntry $entry, PersistentCollection $collection) |
| 31 | { |
| 32 | $assoc = $metadata->associationMappings[$key->association]; |
| 33 | $targetPersister = $this->uow->getEntityPersister($assoc['targetEntity']); |
| 34 | assert($targetPersister instanceof CachedPersister); |
| 35 | $targetRegion = $targetPersister->getCacheRegion(); |
| 36 | $list = []; |
| 37 | $entityEntries = $targetRegion->getMultiple($entry); |
| 38 | if ($entityEntries === null) { |
| 39 | return null; |
| 40 | } |
| 41 | foreach ($entityEntries as $index => $entityEntry) { |
| 42 | $entity = $this->uow->createEntity($entityEntry->class, $entityEntry->resolveAssociationEntries($this->em), self::$hints); |
| 43 | $collection->hydrateSet($index, $entity); |
| 44 | $list[$index] = $entity; |
| 45 | } |
| 46 | $this->uow->hydrationComplete(); |
| 47 | return $list; |
| 48 | } |
| 49 | } |
| 50 |