-
-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
use Doctrine\ORM\EntityRepository; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
use LogicException; | ||
use Symfony\Component\VarExporter\LazyGhostTrait; | ||
use Symfony\Component\VarExporter\LazyObjectInterface; | ||
|
||
use function sprintf; | ||
|
@@ -18,41 +17,58 @@ | |
*/ | ||
class LazyServiceEntityRepository extends EntityRepository implements ServiceEntityRepositoryInterface | ||
{ | ||
use LazyGhostTrait { | ||
createLazyGhost as private; | ||
} | ||
private $registry; | ||
Check failure on line 20 in Repository/LazyServiceEntityRepository.php GitHub Actions / Coding Standards / Coding Standards (8.2)
|
||
private $entityClass; | ||
Check failure on line 21 in Repository/LazyServiceEntityRepository.php GitHub Actions / Coding Standards / Coding Standards (8.2)
|
||
|
||
/** | ||
* @param string $entityClass The class name of the entity this repository manages | ||
* @psalm-param class-string<T> $entityClass | ||
*/ | ||
public function __construct(ManagerRegistry $registry, string $entityClass) | ||
{ | ||
$initializer = function ($instance, $property) use ($registry, $entityClass) { | ||
$manager = $registry->getManagerForClass($entityClass); | ||
$this->registry = $registry; | ||
$this->entityClass = $entityClass; | ||
|
||
if ($manager === null) { | ||
throw new LogicException(sprintf( | ||
'Could not find the entity manager for class "%s". Check your Doctrine configuration to make sure it is configured to load this entity’s metadata.', | ||
$entityClass, | ||
)); | ||
} | ||
if ($this instanceof LazyObjectInterface) { | ||
$this->initialize(); | ||
|
||
parent::__construct($manager, $manager->getClassMetadata($entityClass)); | ||
return; | ||
} | ||
|
||
return $this->$property; | ||
}; | ||
unset($this->_em); | ||
unset($this->_class); | ||
unset($this->_entityName); | ||
} | ||
|
||
if ($this instanceof LazyObjectInterface) { | ||
$initializer($this, '_entityName'); | ||
public function __get($name) | ||
Check failure on line 43 in Repository/LazyServiceEntityRepository.php GitHub Actions / Coding Standards / Coding Standards (8.2)
Check failure on line 43 in Repository/LazyServiceEntityRepository.php GitHub Actions / Coding Standards / Coding Standards (8.2)
|
||
{ | ||
$this->initialize(); | ||
|
||
return; | ||
$scope = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['class'] ?? null; | ||
Check failure on line 47 in Repository/LazyServiceEntityRepository.php GitHub Actions / Coding Standards / Coding Standards (8.2)
|
||
|
||
return (function () use ($name) { return $this->$name; })->bindTo($this, $scope)(); | ||
Check failure on line 49 in Repository/LazyServiceEntityRepository.php GitHub Actions / Coding Standards / Coding Standards (8.2)
Check failure on line 49 in Repository/LazyServiceEntityRepository.php GitHub Actions / Coding Standards / Coding Standards (8.2)
|
||
} | ||
|
||
public function __isset($name): bool | ||
{ | ||
$this->initialize(); | ||
|
||
$scope = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['class'] ?? null; | ||
|
||
return (function () use ($name) { return isset($this->$name); })->bindTo($this, $scope)(); | ||
} | ||
|
||
private function initialize(): void | ||
{ | ||
$manager = $this->registry->getManagerForClass($this->entityClass); | ||
|
||
if ($manager === null) { | ||
throw new LogicException(sprintf( | ||
'Could not find the entity manager for class "%s". Check your Doctrine configuration to make sure it is configured to load this entity’s metadata.', | ||
$this->entityClass, | ||
)); | ||
} | ||
|
||
self::createLazyGhost([ | ||
"\0*\0_em" => $initializer, | ||
"\0*\0_class" => $initializer, | ||
"\0*\0_entityName" => $initializer, | ||
], null, $this); | ||
parent::__construct($manager, $manager->getClassMetadata($this->entityClass)); | ||
} | ||
} |
This file was deleted.