From 71f0cfddcbf3758701fb3ce90ac53162d7b366c9 Mon Sep 17 00:00:00 2001 From: Adir Kuhn Date: Tue, 11 Aug 2020 16:46:05 +0200 Subject: [PATCH] Supports reflection for routes configured in PHP files. (#1701) 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 --- Util/ControllerReflector.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Util/ControllerReflector.php b/Util/ControllerReflector.php index 9a102b4..49fe9d7 100644 --- a/Util/ControllerReflector.php +++ b/Util/ControllerReflector.php @@ -40,21 +40,31 @@ class ControllerReflector * * @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)