Skip to content

Commit

Permalink
Only compute gathered middleware once
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell authored and taylorotwell committed Jan 2, 2017
1 parent fb0d4bd commit 3f4221f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Illuminate/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ class Route
*/
public $parameterNames;

/**
* The computed gathered middleware.
*
* @var array|null
*/
public $computedMiddleware;

/**
* The compiled version of the route.
*
Expand Down Expand Up @@ -659,9 +666,19 @@ public function setAction(array $action)
*/
public function gatherMiddleware()
{
return array_unique(array_merge(
if (! is_null($this->computedMiddleware)) {
return $this->computedMiddleware;
}

// Set incase of an exception, so next time this
// method is called, the exception is not rethrown.
$this->computedMiddleware = [];

$this->computedMiddleware = array_unique(array_merge(
$this->middleware(), $this->controllerMiddleware()
), SORT_REGULAR);

return $this->computedMiddleware;
}

/**
Expand Down

0 comments on commit 3f4221f

Please sign in to comment.