Skip to content

Commit

Permalink
add some methods for manipulating middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 18, 2019
1 parent 3870e03 commit 6f33feb
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/Illuminate/Foundation/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Routing\Pipeline;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Facade;
use InvalidArgumentException;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Throwable;

Expand Down Expand Up @@ -294,6 +295,76 @@ public function pushMiddleware($middleware)
return $this;
}

/**
* Prepend the given middleware to the given middleware group.
*
* @param string $group
* @param string $middleware
* @return $this
*/
public function prependMiddlewareToGroup($group, $middleware)
{
if (! isset($this->middlewareGroups[$group])) {
throw new InvalidArgumentException("The [{$group}] middleware group has not been defined.");
}

if (array_search($middleware, $this->middlewareGroups[$group]) === false) {
array_unshift($this->middlewareGroups[$group], $middleware);
}

return $this;
}

/**
* Append the given middleware to the given middleware group.
*
* @param string $group
* @param string $middleware
* @return $this
*/
public function appendMiddlewareToGroup($group, $middleware)
{
if (! isset($this->middlewareGroups[$group])) {
throw new InvalidArgumentException("The [{$group}] middleware group has not been defined.");
}

if (array_search($middleware, $this->middlewareGroups[$group]) === false) {
$this->middlewareGroups[$group][] = $middleware;
}

return $this;
}

/**
* Prepend the given middleware to the middleware priority list.
*
* @param string $middleware
* @return $this
*/
public function prependToMiddlewarePriority($middleware)
{
if (! in_array($middleware, $this->middlewarePriority)) {
array_unshift($this->middlewarePriority, $middleware);
}

return $this;
}

/**
* Append the given middleware to the middleware priority list.
*
* @param string $middleware
* @return $this
*/
public function appendToMiddlewarePriority($middleware)
{
if (! in_array($middleware, $this->middlewarePriority)) {
$this->middlewarePriority[] = $middleware;
}

return $this;
}

/**
* Get the bootstrap classes for the application.
*
Expand Down

0 comments on commit 6f33feb

Please sign in to comment.