Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
Renumbering argument array before unpacking to controller method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nik Barham committed Jan 19, 2018
1 parent 7cb441d commit ff4b16f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/ControllerParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/
class ControllerParams
{
/** @var string URI that was matched to the route */
public $route;

/** @var string Controller class to call */
public $className;

Expand All @@ -30,8 +33,9 @@ class ControllerParams
/** @var Psr\Container\ContainerInterface Container to pass to constructor */
public $container;

public function __construct($class, $method, $args, Container $container)
public function __construct($route, $class, $method, $args, Container $container)
{
$this->route = $route;
$this->className = $class;
$this->method = $method;
$this->args = $args;
Expand Down
5 changes: 2 additions & 3 deletions src/HandlerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ public function addMiddleware(array $stack)
*/
public function startProcessing(Router $router, Request $request, $uri, $args) : Response
{
$params = new ControllerParams($this->controllerClass, $this->controllerMethod, $args, $router->getServiceContainer());
$params = new ControllerParams($uri, $this->controllerClass, $this->controllerMethod, $args, $router->getServiceContainer());

$request->attributes->set('controller', $params);
$request->attributes->set('router', $router);
$request->attributes->set('route', $uri);
return $this->process($request);
}

Expand Down Expand Up @@ -102,7 +101,7 @@ public function process(Request $request) : Response

// Call controller with request and args
$router->log("Router: Calling Controller: %s@%s", $params->className, $params->method);
$return = (new $params->className($params->container))->{$params->method}($request, ...$params->args);
$return = (new $params->className($params->container))->{$params->method}($request, ...array_values($params->args));
$router->log("Router: Controller Left");

// Instantly return Response objects
Expand Down

0 comments on commit ff4b16f

Please sign in to comment.