Skip to content

Commit

Permalink
fixed terminable middlewares assigned to the controller
Browse files Browse the repository at this point in the history
  • Loading branch information
n7olkachev committed Mar 28, 2016
1 parent 2bf0851 commit 84eb430
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/ControllerDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected function callWithinStack($instance, $route, $request, $method)
* @param string $method
* @return array
*/
protected function getMiddleware($instance, $method)
public function getMiddleware($instance, $method)
{
$results = new Collection;

Expand Down
13 changes: 12 additions & 1 deletion src/Illuminate/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,18 @@ protected function extractOptionalParameters()
public function middleware($middleware = null)
{
if (is_null($middleware)) {
return (array) Arr::get($this->action, 'middleware', []);
$middlewares = (array) Arr::get($this->action, 'middleware', []);

if (is_string($this->action['uses'])) {
list($class, $method) = explode('@', $this->action['uses']);
$controller = $this->container->make($class);

$controllerMiddlewares = (new ControllerDispatcher($this->router, $this->container))
->getMiddleware($controller, $method);
$middlewares = array_merge($middlewares, $controllerMiddlewares);
}

return $middlewares;
}

if (is_string($middleware)) {
Expand Down

1 comment on commit 84eb430

@johnboy-leeds
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to get some more background on this and the reason for this change.

Our application had been built on the assumption that the Middleware is run BEFORE the controller is constructed as in some places the constructors are dependant on data set in the middleware. As such upgrading broke our application.

I am able to get round this by extending this class and reverting the changes but wondering if you can shed a bit more light on what the reason behind this was so we can foresee any problems our way of working may cause.

Please sign in to comment.