Skip to content
Permalink
Browse files

add some methods for manipulating middleware

  • Loading branch information
taylorotwell committed Dec 18, 2019
1 parent 3870e03 commit 6f33feba124d4a7ff2af4f3ed18583d67fb68f7c
Showing with 71 additions and 0 deletions.
  1. +71 −0 src/Illuminate/Foundation/Http/Kernel.php
@@ -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;

@@ -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.
*

0 comments on commit 6f33feb

Please sign in to comment.
You can’t perform that action at this time.