Skip to content

Commit

Permalink
Fix proxies + getter issues. Fixes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
maxiloc committed Dec 7, 2015
1 parent 642cab5 commit b32767a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
14 changes: 4 additions & 10 deletions Indexer/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -151,7 +152,7 @@ public function discoverEntity($entity_or_class, EntityManager $em)
if ($reflClass->isAbstract()) {
return false;
}

$entity = $reflClass->newInstanceWithoutConstructor();
}

Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion Indexer/ManualIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
}

Expand Down
2 changes: 1 addition & 1 deletion Mapping/Loader/AnnotationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit b32767a

Please sign in to comment.