From b32767ac472f318ab1f7600065c2876bfd285ebc Mon Sep 17 00:00:00 2001 From: Maxime Locqueville Date: Mon, 7 Dec 2015 16:31:44 +0100 Subject: [PATCH] Fix proxies + getter issues. Fixes #33 --- Indexer/Indexer.php | 14 ++++---------- Indexer/ManualIndexer.php | 2 +- Mapping/Loader/AnnotationLoader.php | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Indexer/Indexer.php b/Indexer/Indexer.php index 7d1f97b1..742e1981 100644 --- a/Indexer/Indexer.php +++ b/Indexer/Indexer.php @@ -4,6 +4,7 @@ use Doctrine\Common\Persistence\Proxy; use Doctrine\ORM\EntityManager; +use Symfony\Component\PropertyAccess\PropertyAccess; use Algolia\AlgoliaSearchBundle\Exception\UnknownEntity; use Algolia\AlgoliaSearchBundle\Exception\NoPrimaryKey; @@ -151,7 +152,7 @@ public function discoverEntity($entity_or_class, EntityManager $em) if ($reflClass->isAbstract()) { return false; } - + $entity = $reflClass->newInstanceWithoutConstructor(); } @@ -287,17 +288,10 @@ function isEntity(EntityManager $em, $class) return ! $em->getMetadataFactory()->isTransient($class); } - /** - * OOP? Encapsulation? No thanks! :) - * http://php.net/manual/en/closure.bind.php - */ private function extractPropertyValue($entity, $field, $depth) { - $privateGetter = \Closure::bind(function ($field) { - return $this->$field; - }, $entity, $entity); - - $value = $privateGetter($field); + $accessor = PropertyAccess::createPropertyAccessor(); + $value = $accessor->getValue($entity, $field); if ($value instanceof \Doctrine\Common\Collections\Collection) { diff --git a/Indexer/ManualIndexer.php b/Indexer/ManualIndexer.php index 3d642c92..de97e4be 100644 --- a/Indexer/ManualIndexer.php +++ b/Indexer/ManualIndexer.php @@ -232,7 +232,7 @@ public function reIndex($entityName, array $options = array()) if (!$this->indexer->discoverEntity($className, $this->entityManager)) { throw new NotAnAlgoliaEntity( - 'Tried to index entity of class `'.get_class($className).'`, which is not recognized as an entity to index.' + 'Tried to index entity of class `'.$className.'`, which is not recognized as an entity to index.' ); } diff --git a/Mapping/Loader/AnnotationLoader.php b/Mapping/Loader/AnnotationLoader.php index 58f2f0c4..c69f9031 100644 --- a/Mapping/Loader/AnnotationLoader.php +++ b/Mapping/Loader/AnnotationLoader.php @@ -57,7 +57,7 @@ public function getMetaData($entity, EntityManager $em) $description = new Description($class); - $refl = new \ReflectionClass($entity); + $refl = new \ReflectionClass($class); $reader = $this->getAnnotationReader();