Skip to content

Commit

Permalink
Checks the existence of a public getId method
Browse files Browse the repository at this point in the history
  • Loading branch information
alterphp committed Dec 2, 2019
1 parent 55aa7fb commit f24ccc0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Helper/EmbeddedListHelper.php
Expand Up @@ -137,7 +137,17 @@ public function guessDefaultFilter(string $entityFqcn, string $parentEntityPrope
$relatedItems = PropertyAccess::createPropertyAccessor()->getValue(
$parentEntity, $parentEntityProperty
);
$itemIds = $relatedItems->map(function ($entity) {
$itemIds = $relatedItems->map(function (object $entity) {
$hasGetIdMethod = false;
try {
$reflGetIdMethod = new \ReflectionMethod($entity, 'getId');
$hasGetIdMethod = $reflGetIdMethod->isPublic();
} catch (\ReflectionException $e) {}

if (!$hasGetIdMethod) {
throw new \RuntimeException('EmbeddedListHelper requires a public `getId` method on root entity in order to guess filters to apply!');
}

return $entity->getId();
});

Expand Down

0 comments on commit f24ccc0

Please sign in to comment.