Skip to content

Commit

Permalink
MultiGetCollectionHydrator depends knows the multi-get region
Browse files Browse the repository at this point in the history
  • Loading branch information
goetas committed Jan 17, 2015
1 parent a8f871c commit 01e3604
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Cache/DefaultCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function buildCollectionHydrator(EntityManagerInterface $em, array $mappi
$targetRegion = $targetPersister->getCacheRegion();

if ($targetRegion instanceof MultiGetRegion) {
return new MultiGetCollectionHydrator($em);
return new MultiGetCollectionHydrator($em, $targetRegion);
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions lib/Doctrine/ORM/Cache/MultiGetCollectionHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class MultiGetCollectionHydrator implements CollectionHydrator
*/
private $uow;

/**
* @var MultiGetRegion
*/
private $targetRegion;

/**
* @var array
*/
Expand All @@ -52,10 +57,11 @@ class MultiGetCollectionHydrator implements CollectionHydrator
/**
* @param \Doctrine\ORM\EntityManagerInterface $em The entity manager.
*/
public function __construct(EntityManagerInterface $em)
public function __construct(EntityManagerInterface $em, MultiGetRegion $targetRegion)
{
$this->em = $em;
$this->uow = $em->getUnitOfWork();
$this->targetRegion = $targetRegion;
}

/**
Expand All @@ -78,16 +84,14 @@ public function buildCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key
public function loadCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, CollectionCacheEntry $entry, PersistentCollection $collection)
{
$assoc = $metadata->associationMappings[$key->association];
$targetPersister = $this->uow->getEntityPersister($assoc['targetEntity']);
$targetRegion = $targetPersister->getCacheRegion();
$list = array();

$keys = array();
foreach ($entry->identifiers as $index => $identifier) {
$keys[$index] = new EntityCacheKey($assoc['targetEntity'], $identifier);
}

$entityEntries = $targetRegion->getMulti($keys);
$entityEntries = $this->targetRegion->getMulti($keys);

if ($entityEntries === null) {
return null;
Expand Down

0 comments on commit 01e3604

Please sign in to comment.