mirror of
https://github.com/flarum/core.git
synced 2025-07-29 04:30:56 +02:00
Middleware extender (#1952)
This commit is contained in:
committed by
Franz Liedke
parent
7eb3ece6ad
commit
441d74f1af
41
framework/core/src/Extend/Middleware.php
Normal file
41
framework/core/src/Extend/Middleware.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Flarum\Extend;
|
||||||
|
|
||||||
|
use Flarum\Extension\Extension;
|
||||||
|
use Illuminate\Contracts\Container\Container;
|
||||||
|
use Zend\Stratigility\MiddlewarePipe;
|
||||||
|
|
||||||
|
class Middleware implements ExtenderInterface
|
||||||
|
{
|
||||||
|
protected $middlewares = [];
|
||||||
|
protected $frontend;
|
||||||
|
|
||||||
|
public function __construct(string $frontend)
|
||||||
|
{
|
||||||
|
$this->frontend = $frontend;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add($middleware)
|
||||||
|
{
|
||||||
|
$this->middlewares[] = $middleware;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function extend(Container $container, Extension $extension = null)
|
||||||
|
{
|
||||||
|
$container->resolving("flarum.{$this->frontend}.middleware", function (MiddlewarePipe $pipe) use ($container) {
|
||||||
|
foreach ($this->middlewares as $middleware) {
|
||||||
|
$pipe->pipe($container->make($middleware));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user