1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 22:10:45 +02:00

Merge pull request #4266 from marc1706/ticket/13502

[ticket/13502] Handle callable functions/objects in controller resolver

* marc1706/ticket/13502:
  [ticket/13502] Also cover passing object to resolver in tests
  [ticket/13502] Test getArguments() method of controller resolver
  [ticket/13502] Fix coding style
  [ticket/13502] Controller resolver should handle callable functions and objects
This commit is contained in:
Tristan Darricau
2016-04-03 16:04:59 +02:00
3 changed files with 78 additions and 15 deletions

View File

@@ -126,9 +126,21 @@ class resolver implements ControllerResolverInterface
*/
public function getArguments(Request $request, $controller)
{
// At this point, $controller contains the object and method name
list($object, $method) = $controller;
$mirror = new \ReflectionMethod($object, $method);
// At this point, $controller should be a callable
if (is_array($controller))
{
list($object, $method) = $controller;
$mirror = new \ReflectionMethod($object, $method);
}
else if (is_object($controller) && !$controller instanceof \Closure)
{
$mirror = new \ReflectionObject($controller);
$mirror = $mirror->getMethod('__invoke');
}
else
{
$mirror = new \ReflectionFunction($controller);
}
$arguments = array();
$parameters = $mirror->getParameters();