Skip to content

Commit

Permalink
Supports reflection for routes configured in PHP files. (#1701)
Browse files Browse the repository at this point in the history
By default the PHP configuration routes returns an array with the controller name and method, since the reflection class was typed for string only this was causing an exception when the user was not using YAML or XML configuration.
This changes removes the string type hint from the method and checks if it's an array or string to do the reflection.

Co-authored-by: Adir Kuhn <adir@123inkt.nl>
  • Loading branch information
adirkuhn and Adir Kuhn committed Aug 11, 2020
1 parent edf6b70 commit 71f0cfd
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Util/ControllerReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,31 @@ public function __construct(ContainerInterface $container)
*
* @return \ReflectionMethod|null
*/
public function getReflectionMethod(string $controller)
public function getReflectionMethod($controller)
{
$callable = $this->getClassAndMethod($controller);
if (null === $callable) {
return;
if (is_string($controller)) {
$controller = $this->getClassAndMethod($controller);
if (null === $controller) {
return null;
}
}

list($class, $method) = $callable;
return $this->geReflectionMethodByClassNameAndMethodName(...$controller);
}

/**
* @return \ReflectionMethod|null
*/
public function geReflectionMethodByClassNameAndMethodName(string $class, string $method)
{
try {
return new \ReflectionMethod($class, $method);
} catch (\ReflectionException $e) {
// In case we can't reflect the controller, we just
// ignore the route
}

return null;
}

private function getClassAndMethod(string $controller)
Expand Down

0 comments on commit 71f0cfd

Please sign in to comment.