src/Leevel/Router/MiddlewareParser.php
public function handle(array $middlewares): array
    {
        $middlewareGroups = $this->router->getMiddlewareGroups();
        $middlewareAlias = $this->router->getMiddlewareAlias();

        $result = [];

        foreach ($middlewares as $m) {
            if (!is_string($m)) {
                throw new InvalidArgumentException('Middleware only allowed string.');
            }

            list($m, $params) = $this->parseMiddleware($m);

            if (isset($middlewareGroups[$m])) {
                $temp = is_array($middlewareGroups[$m]) ?
                    $middlewareGroups[$m] : [$middlewareGroups[$m]];

                foreach ($temp as $item) {
                    list($item, $params) = $this->parseMiddleware($item);

                    $result[] = $this->middlewareName($middlewareAlias[$item] ?? $item, $params);
                }
            } else {
                $result[] = $this->middlewareName($middlewareAlias[$m] ?? $m, $params);
            }
        }

        $result = [
            'handle'    => $this->normalizeMiddleware($result, 'handle'),
            'terminate' => $this->normalizeMiddleware($result, 'terminate'),
        ];

        if (empty($result['handle']) && empty($result['terminate'])) {
            return [];
        }

        return $result;
    }
public function handle(array $middlewares): array
    {
        $middlewareGroups = $this->router->getMiddlewareGroups();
        $middlewareAlias = $this->router->getMiddlewareAlias();

        $result = [];

        foreach ($middlewares as $m) {
            if (!is_string($m)) {
                throw new InvalidArgumentException('Middleware only allowed string.');
            }

            list($m, $params) = $this->parseMiddleware($m);

            if (isset($middlewareGroups[$m])) {
                $temp = is_array($middlewareGroups[$m]) ?
                    $middlewareGroups[$m] : [$middlewareGroups[$m]];

                foreach ($temp as $item) {
                    list($item, $params) = $this->parseMiddleware($item);

                    $result[] = $this->middlewareName($middlewareAlias[$item] ?? $item, $params);
                }
            } else {
                $result[] = $this->middlewareName($middlewareAlias[$m] ?? $m, $params);
            }
        }

        $result = [
            'handle'    => $this->normalizeMiddleware($result, 'handle'),
            'terminate' => $this->normalizeMiddleware($result, 'terminate'),
        ];

        if (empty($result['handle']) && empty($result['terminate'])) {
            return [];
        }

        return $result;
    }
解析中间件
最多 2 个层级支持

@param array $middlewares

@return array