Middleware extender (#1952)

This commit is contained in:
Matt Kilgore 2019-12-12 03:22:04 -05:00 committed by Franz Liedke
parent 9b00244454
commit aba291c542

41
src/Extend/Middleware.php Normal file
View 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));
}
});
}
}