This commit is contained in:
2021-09-24 18:42:30 +08:00
parent e5efe8eb84
commit 5f2fab79e2
2 changed files with 13 additions and 3 deletions
+1
View File
@@ -5,6 +5,7 @@ namespace Http\Handler\Abstracts;
use Http\Handler\Handler as CHl;
use Http\Message\ServerRequest;
use Kiri\Core\Help;
use Kiri\Events\EventDispatch;
use Kiri\Kiri;
use Kiri\Proxy\AspectProxy;
use Psr\Http\Message\ResponseInterface;
+12 -3
View File
@@ -16,6 +16,10 @@ use Kiri\Abstracts\BaseObject;
class MiddlewareManager extends BaseObject
{
/**
* @var array<string, Iterator>
*/
private static array $_middlewares = [];
@@ -54,7 +58,7 @@ class MiddlewareManager extends BaseObject
* @param $handler
* @return mixed
*/
public static function get($handler): mixed
public static function get($handler): Iterator
{
if (!($handler instanceof Closure)) {
if (!isset(static::$_middlewares[$handler[0]])) {
@@ -63,9 +67,14 @@ class MiddlewareManager extends BaseObject
if (!isset(static::$_middlewares[$handler[0]][$handler[1]])) {
static::$_middlewares[$handler[0]][$handler[1]] = new Iterator();
}
return static::$_middlewares[$handler[0]][$handler[1]];
/** @var Iterator $iterator */
$iterator = static::$_middlewares[$handler[0]][$handler[1]];
if ($iterator->count() > 0 && !$iterator->valid()) {
$iterator->rewind();
}
return $iterator;
}
return new Iterator();
return di(Iterator::class);
}