Ignore ReflectionException for "magic" JMS\Accessor methods (#1715)

* Update JMSModelDescriber.php

Ignore ReflectionException thrown when getter or setter from JMS\ Accessor are "magic" methods.

* Add tests to avoid future regressions

* CS

Co-authored-by: Guilhem Niot <guilhem.niot@gmail.com>
This commit is contained in:
Paul Dugas 2020-09-09 02:27:47 -04:00 committed by Guilhem Niot
parent d9f1611f72
commit 429d809f41
2 changed files with 25 additions and 5 deletions

View File

@ -93,11 +93,14 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
$reflections[] = new \ReflectionProperty($item->class, $item->name); $reflections[] = new \ReflectionProperty($item->class, $item->name);
} }
if (null !== $item->getter) { try {
$reflections[] = new \ReflectionMethod($item->class, $item->getter); if (null !== $item->getter) {
} $reflections[] = new \ReflectionMethod($item->class, $item->getter);
if (null !== $item->setter) { }
$reflections[] = new \ReflectionMethod($item->class, $item->setter); if (null !== $item->setter) {
$reflections[] = new \ReflectionMethod($item->class, $item->setter);
}
} catch (\ReflectionExceptions $ignored) {
} }
$groups = $this->computeGroups($context, $item->type); $groups = $this->computeGroups($context, $item->type);

View File

@ -37,9 +37,26 @@ class VirtualProperty
*/ */
private $user; private $user;
/**
* @Serializer\Accessor(getter="getFoo", setter="setFoo")
* @Serializer\Type("string")
*
* Ensures https://github.com/nelmio/NelmioApiDocBundle/issues/1708 is fixed.
*/
private $virtualprop;
public function __construct() public function __construct()
{ {
$this->user = new User(); $this->user = new User();
$this->user->setEmail('dummy@test.com'); $this->user->setEmail('dummy@test.com');
} }
public function __call(string $name, array $arguments)
{
if ('getFoo' === $name || 'setFoo' === $name) {
return 'Success';
}
throw new \LogicException(sprintf('%s::__call does not implement this function.', __CLASS__));
}
} }