DDC-3683 - #1380 - reverting BC break, annotating correct types, cs fixes
This commit is contained in:
parent
fff56c7f3f
commit
ed1c4de2b6
@ -20,33 +20,20 @@
|
|||||||
namespace Doctrine\ORM\Event;
|
namespace Doctrine\ORM\Event;
|
||||||
|
|
||||||
use Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs as BaseLoadClassMetadataEventArgs;
|
use Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs as BaseLoadClassMetadataEventArgs;
|
||||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
|
||||||
use Doctrine\ORM\EntityManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that holds event arguments for a loadMetadata event.
|
* Class that holds event arguments for a loadMetadata event.
|
||||||
*
|
*
|
||||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
|
*
|
||||||
|
* Note: method annotations are used instead of method overrides (due to BC policy)
|
||||||
|
*
|
||||||
|
* @method __construct(\Doctrine\ORM\Mapping\ClassMetadata $classMetadata, \Doctrine\ORM\EntityManager $objectManager)
|
||||||
|
* @method \Doctrine\ORM\EntityManager getClassMetadata()
|
||||||
*/
|
*/
|
||||||
class LoadClassMetadataEventArgs extends BaseLoadClassMetadataEventArgs
|
class LoadClassMetadataEventArgs extends BaseLoadClassMetadataEventArgs
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @param ClassMetadata $classMetadata
|
|
||||||
* @param EntityManager $entityManager
|
|
||||||
*/
|
|
||||||
function __construct(ClassMetadata $classMetadata, EntityManager $entityManager)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
We use our own constructor here to enforce type-hinting requirements,
|
|
||||||
since both inputs are specialized subclasses compared to what the super-
|
|
||||||
class is willing to accept.
|
|
||||||
|
|
||||||
In particular, we want to have EntityManager rather than ObjectManager.
|
|
||||||
*/
|
|
||||||
parent::__construct($classMetadata, $entityManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve associated EntityManager.
|
* Retrieve associated EntityManager.
|
||||||
*
|
*
|
||||||
@ -54,20 +41,6 @@ class LoadClassMetadataEventArgs extends BaseLoadClassMetadataEventArgs
|
|||||||
*/
|
*/
|
||||||
public function getEntityManager()
|
public function getEntityManager()
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
We can safely assume our ObjectManager is also an EventManager due to
|
|
||||||
our restrictions in the constructor.
|
|
||||||
*/
|
|
||||||
return $this->getObjectManager();
|
return $this->getObjectManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the associated ClassMetadata.
|
|
||||||
*
|
|
||||||
* @return \Doctrine\ORM\Mapping\ClassMetadata
|
|
||||||
*/
|
|
||||||
public function getClassMetadata()
|
|
||||||
{
|
|
||||||
return parent::getClassMetadata();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
namespace Doctrine\Tests\EventListener;
|
namespace Doctrine\Tests\EventListener;
|
||||||
|
|
||||||
use Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs;
|
use Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs;
|
||||||
use Doctrine\Common\Persistence\ObjectManager;
|
|
||||||
use Doctrine\ORM\EntityManager;
|
use Doctrine\ORM\EntityManager;
|
||||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||||
|
|
||||||
@ -38,16 +37,19 @@ class CacheMetadataListener
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ClassMetadata $metadata
|
* @param ClassMetadata $metadata
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function isVisited(ClassMetaData $metadata) {
|
private function isVisited(ClassMetaData $metadata)
|
||||||
|
{
|
||||||
return isset($this->enabledItems[$metadata->getName()]);
|
return isset($this->enabledItems[$metadata->getName()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ClassMetadata $metadata
|
* @param ClassMetadata $metadata
|
||||||
*/
|
*/
|
||||||
private function recordVisit(ClassMetaData $metadata) {
|
private function recordVisit(ClassMetaData $metadata)
|
||||||
|
{
|
||||||
$this->enabledItems[$metadata->getName()] = true;
|
$this->enabledItems[$metadata->getName()] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +57,8 @@ class CacheMetadataListener
|
|||||||
* @param ClassMetadata $metadata
|
* @param ClassMetadata $metadata
|
||||||
* @param EntityManager $em
|
* @param EntityManager $em
|
||||||
*/
|
*/
|
||||||
protected function enableCaching(ClassMetadata $metadata, EntityManager $em) {
|
protected function enableCaching(ClassMetadata $metadata, EntityManager $em)
|
||||||
|
{
|
||||||
if ($this->isVisited($metadata)) {
|
if ($this->isVisited($metadata)) {
|
||||||
return; // Already handled in the past
|
return; // Already handled in the past
|
||||||
}
|
}
|
||||||
@ -73,12 +75,9 @@ class CacheMetadataListener
|
|||||||
|
|
||||||
$this->recordVisit($metadata);
|
$this->recordVisit($metadata);
|
||||||
|
|
||||||
/*
|
// only enable association-caching when the target has already been
|
||||||
* Only enable association-caching when the target has already been
|
// given caching settings
|
||||||
* given caching settings
|
|
||||||
*/
|
|
||||||
foreach ($metadata->associationMappings as $mapping) {
|
foreach ($metadata->associationMappings as $mapping) {
|
||||||
|
|
||||||
$targetMeta = $em->getClassMetadata($mapping['targetEntity']);
|
$targetMeta = $em->getClassMetadata($mapping['targetEntity']);
|
||||||
$this->enableCaching($targetMeta, $em);
|
$this->enableCaching($targetMeta, $em);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user