mirror of
https://github.com/flarum/framework.git
synced 2024-11-22 12:48:28 +08:00
Middleware extender (#1952)
This commit is contained in:
parent
9b00244454
commit
aba291c542
41
src/Extend/Middleware.php
Normal file
41
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));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user