Skip to content

Commit 6f33feb

Browse files
committed
add some methods for manipulating middleware
1 parent 3870e03 commit 6f33feb

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

src/Illuminate/Foundation/Http/Kernel.php

+71
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Routing\Pipeline;
1111
use Illuminate\Routing\Router;
1212
use Illuminate\Support\Facades\Facade;
13+
use InvalidArgumentException;
1314
use Symfony\Component\Debug\Exception\FatalThrowableError;
1415
use Throwable;
1516

@@ -294,6 +295,76 @@ public function pushMiddleware($middleware)
294295
return $this;
295296
}
296297

298+
/**
299+
* Prepend the given middleware to the given middleware group.
300+
*
301+
* @param string $group
302+
* @param string $middleware
303+
* @return $this
304+
*/
305+
public function prependMiddlewareToGroup($group, $middleware)
306+
{
307+
if (! isset($this->middlewareGroups[$group])) {
308+
throw new InvalidArgumentException("The [{$group}] middleware group has not been defined.");
309+
}
310+
311+
if (array_search($middleware, $this->middlewareGroups[$group]) === false) {
312+
array_unshift($this->middlewareGroups[$group], $middleware);
313+
}
314+
315+
return $this;
316+
}
317+
318+
/**
319+
* Append the given middleware to the given middleware group.
320+
*
321+
* @param string $group
322+
* @param string $middleware
323+
* @return $this
324+
*/
325+
public function appendMiddlewareToGroup($group, $middleware)
326+
{
327+
if (! isset($this->middlewareGroups[$group])) {
328+
throw new InvalidArgumentException("The [{$group}] middleware group has not been defined.");
329+
}
330+
331+
if (array_search($middleware, $this->middlewareGroups[$group]) === false) {
332+
$this->middlewareGroups[$group][] = $middleware;
333+
}
334+
335+
return $this;
336+
}
337+
338+
/**
339+
* Prepend the given middleware to the middleware priority list.
340+
*
341+
* @param string $middleware
342+
* @return $this
343+
*/
344+
public function prependToMiddlewarePriority($middleware)
345+
{
346+
if (! in_array($middleware, $this->middlewarePriority)) {
347+
array_unshift($this->middlewarePriority, $middleware);
348+
}
349+
350+
return $this;
351+
}
352+
353+
/**
354+
* Append the given middleware to the middleware priority list.
355+
*
356+
* @param string $middleware
357+
* @return $this
358+
*/
359+
public function appendToMiddlewarePriority($middleware)
360+
{
361+
if (! in_array($middleware, $this->middlewarePriority)) {
362+
$this->middlewarePriority[] = $middleware;
363+
}
364+
365+
return $this;
366+
}
367+
297368
/**
298369
* Get the bootstrap classes for the application.
299370
*

0 commit comments

Comments
 (0)