This commit is contained in:
2021-09-24 18:46:25 +08:00
parent 5f2fab79e2
commit bfd9f07780
2 changed files with 9 additions and 18 deletions
+3 -14
View File
@@ -56,23 +56,12 @@ class MiddlewareManager extends BaseObject
/**
* @param $handler
* @return mixed
* @return Iterator|null
*/
public static function get($handler): Iterator
public static function get($handler): ?Iterator
{
if (!($handler instanceof Closure)) {
if (!isset(static::$_middlewares[$handler[0]])) {
static::$_middlewares[$handler[0]] = [];
}
if (!isset(static::$_middlewares[$handler[0]][$handler[1]])) {
static::$_middlewares[$handler[0]][$handler[1]] = new Iterator();
}
/** @var Iterator $iterator */
$iterator = static::$_middlewares[$handler[0]][$handler[1]];
if ($iterator->count() > 0 && !$iterator->valid()) {
$iterator->rewind();
}
return $iterator;
return static::$_middlewares[$handler[0]][$handler[1]] ?? null;
}
return di(Iterator::class);
}