From abdf04516a1340019099053f67cd04318e6c6fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 28 Oct 2017 21:24:57 +0100 Subject: [PATCH] Calculate metadata calculation lazily Closes #53 --- src/Bridge/Doctrine/Persister/ObjectManagerPersister.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Bridge/Doctrine/Persister/ObjectManagerPersister.php b/src/Bridge/Doctrine/Persister/ObjectManagerPersister.php index 2c52f5dd..70a87dfe 100644 --- a/src/Bridge/Doctrine/Persister/ObjectManagerPersister.php +++ b/src/Bridge/Doctrine/Persister/ObjectManagerPersister.php @@ -32,14 +32,13 @@ private $objectManager; /** - * @var array Values are FQCN of persistable objects + * @var array|null Values are FQCN of persistable objects */ private $persistableClasses; public function __construct(ObjectManager $manager) { $this->objectManager = $manager; - $this->persistableClasses = array_flip($this->getPersistableClasses($manager)); } /** @@ -47,6 +46,10 @@ public function __construct(ObjectManager $manager) */ public function persist($object) { + if (null === $this->persistableClasses) { + $this->persistableClasses = array_flip($this->getPersistableClasses($this->objectManager)); + } + if (isset($this->persistableClasses[get_class($object)])) { $this->objectManager->persist($object); }