Uploaded image for project: 'phpBB'
  1. phpBB
  2. PHPBB-13502

controller resolver should handle callable functions and objects

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major Major
    • 3.2.0-RC1
    • 3.2.0-dev
    • None
    • None

      Implementing Symfony kernel's kernel.controller allows client to change the controller as needed.

      If the method calls

      $event->setController(function() use ($e) {
                 return new Response($e->getMessage());
      });
      

      Then an error is generated because \phpbb\controller\resolver::getArguments expects controller to be an array rather than any callable, which is functionality that Symfony supports.

      The following code fixes this issue:

      public function getArguments(Request $request, $controller)
      	{
      		// 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);
      		}
      

            Marc Marc
            rfdy rfdy [X] (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: