デバッグ用ミドルウェアリストを作成する

@return  MiddlewareInterface[]
191594
private function createWrapperMiddlewares(){
        $middlewares    = [];

        $middlewares[]  = $this->container->get("core.middleware.error");

        if($this->isDebug()){
            $middlewares[]  = $this->container->get("core.middleware.debug");
        }

        $middlewares[]  = $this->container->get("core.middleware.wrapper");

        return $middlewares;
    }
709352
protected function gatherInvokerMiddleware($middleware)
    {
        $nameMiddleware = $this->config['name_middleware'] ?? [];
        $middlewareGroups = $this->config['middleware_groups'] ?? [];

        return Collection::make($middleware)->map(function ($middleware) use ($nameMiddleware, $middlewareGroups) {
            return (array) MiddlewareNameResolver::resolve($middleware, $nameMiddleware, $middlewareGroups);
        })->flatten()->all();
    }
1362613
private function loadMiddleware()
    {
        $this->middleware = [];

        $config = Container::getInstance()->get('config');
        $list   = $config->get('global.middleware');

        foreach ($list as $name => $conf) {
            $services = $conf['services'];
            foreach ($services as $service) {
                // todo
            }
            $this->middleware[] = new $conf['class']($config);
        }
    }
1111705
public function expandMiddlewareMolecule( $middleware ) {
		$pieces = explode( ':', $middleware, 2 );

		if ( count( $pieces ) > 1 ) {
			return [array_merge( [$this->expandMiddlewareAtom( $pieces[0] )], explode( ',', $pieces[1] ) )];
		}

		if ( isset( $this->middleware_groups[ $middleware ] ) ) {
			return $this->expandMiddlewareGroup( $middleware );
		}

		return [[$this->expandMiddlewareAtom( $middleware )]];
	}
822303
public function gatherMiddlewareStack(): array
    {
        $middlewares = $this->getMiddlewareStack();
        // If there is a parent group, we merge both middleware stacks (Route + RouteGroup).
        if ($group = $this->getParentGroup()) {
            $middlewares = array_merge($middlewares, $group->getMiddlewareStack());
        }

        return $middlewares;
    }
498598
public function addMiddlewares(...$middlewares): array
    {
        $stack = $this->getMiddlewareStack(true);
        foreach ($middlewares as $middleware) {
            $stack->append($middleware);
        }
        return $middlewares;
    }
439206
protected function getApiKeyMiddleware()
    {
        $handleRequest = function (RequestInterface $request) {
            return $request->withUri(Uri::withQueryValue(
                $request->getUri(),
                static::PARAM_API_KEY,
                $this->apiKey
            ));
        };

        return Middleware::mapRequest($handleRequest);
    }
316827
public function resolve($middlewares)
    {
        $last = function ($request, $response) {
            // no op
        };
        while ($middleware = array_pop($middlewares)) {
            if (is_object($middleware)) {
                if (method_exists($middleware, '__invoke')) {
                    $middleware = [$middleware, '__invoke'];
                }
            }

            if (!is_callable($middleware)) {
                throw new \InvalidArgumentException('Middle needs to be callable');
            }

            $last = function () use ($middleware, $last) {
                $args = func_get_args();
                $args[] = $last;
                return call_user_func_array($middleware, $args);
            };
        }
        return $last;
    }
955171
public function getMiddlewareChain()
    {
        $middlewares = array_reverse(iterator_to_array(clone $this->getMiddlewares()));

        $chain = new Psr7ChainBuilder();

        foreach ($middlewares as $middleware) {
            $data = [];

            if (is_array($middleware)) {
                $data = $middleware;
                $middleware = $data['middleware'];

                unset($data['middleware']);
            }

            if ($middleware instanceof ClassMeta
                || (is_string($middleware) && is_subclass_of($middleware, AbstractWebMiddleware::class))) {
                $middleware = new Psr7Middleware($this->container->newInstance($middleware, $data));
            } elseif ($middleware instanceof \Closure) {
                $middleware->bindTo($this);
            } elseif ($middleware === false) {
                continue;
            }

            $chain->add($middleware);
        }

        return $chain;
    }
976589
public function getMiddleware() : array
    {
        if (!$this->providesMiddleware()) {
            return [];
        }

        $allControllerMiddleware = array_filter(
            $this->getController()->getControllerMiddleware(),
            function (ControllerMiddleware $middleware) {
                return !$middleware->excludedForMethod($this->controllerMethod);
            }
        );

        return array_map(
            function ($controllerMiddleware) {
                return $controllerMiddleware->middleware();
            },
            $allControllerMiddleware
        );
    }
711433
private function getRouteAsMiddleware(ResultInterface $result): MiddlewareInterface
    {
        $callback = $result->getRoute()->getCallback();

        // resolve the callback
        if (is_string($callback)) {
            // resolve using the container
            $callback = ($this->container ? $this->container->get($callback) : null);
        }

        if (is_array($callback) && count($callback) === 2) {
            // resolve the [class, method] call
            list($class, $method) = $callback;
            $callback = ($this->container ? function ($request, $response) use ($class, $method) {
                $class = $this->container->get($class);
                return $class->$method($request, $response);
            } : null);
        }

        if ($callback instanceof MiddlewareInterface) {
            // return the middleware
            return $callback;
        }

        if (is_callable($callback)) {
            return new Route($callback);
        }

        throw new CannotExecuteRouteException('Dispatch doesn\'t know how to handle the callback');
    }
451304
private function decorate($middleware): MiddlewareInterface
    {
        if ($middleware instanceof MiddlewareInterface) {
            return $middleware;
        } elseif ($middleware instanceof RequestHandlerInterface) {
            return new RequestHandlerMiddleware($middleware);
        } elseif ($middleware instanceof ResponseInterface) {
            return new FixedResponseMiddleware($middleware);
        } elseif (is_callable($middleware)) {
            return new CallableMiddleware($middleware);
        } elseif (is_string($middleware)) {
            return new LazyLoadingMiddleware($middleware, $this->container);
        } else {
            throw new InvalidArgumentException(sprintf(
                'Middleware "%s" is neither a string service name, an autoloadable class name, a PHP callable, or an instance of %s/%s/%s',
                is_object($middleware) ? get_class($middleware) : gettype($middleware),
                MiddlewareInterface::class, ResponseInterface::class, RequestHandlerInterface::class
            ));
        }
    }
682443
private function getGroupMiddleware() : array
    {
        $middleware = [];

        foreach ($this->groupOptionsStack as $groupOptions) {
            if (isset($groupOptions['middleware'])) {
                if (!is_array($groupOptions['middleware'])) {
                    $groupOptions['middleware'] = [$groupOptions['middleware']];
                }

                $middleware = array_merge($middleware, $groupOptions['middleware']);
            }
        }

        return $middleware;
    }
995750
private static function middleware()
    {
        $files = ['Filters', 'Middleware'];
        $folder = static::$root.'Http/Middleware'.'/';

        self::call($files, $folder);

        $files = ['MiddlewareNotFoundException', 'MiddlewareWallException'];
        $folder = static::$root.'Http/Middleware/Exceptions'.'/';

        self::call($files, $folder);
    }
592661
public function getallRouting():array
    {
        $routings = array();
        $appc = $this->getMaster("Apps");
        $apps = $appc->getAllApps();

        $routingArray = array();
        $pattern = '/\s*/m';
        $replace = '';

        foreach ($apps as $one) {
            $routers = scandir(FEnv::get("framework.root") . "apps/" . $one->name . "/Routing");
            foreach ($routers as $file) {
                $scope = null;
                if ($file == "." || $file == ".." || false === strpos($file, ".merc")) {
                    continue;
                }
                if (($router = fopen((FEnv::get("framework.apps")) .
                    $one->name . "/Routing/" . $file, "r"))) {
                    $rtarray = array("activity" => "", "path" => "", "name" => "");
                    $start = 0;
                    $end = 0;
                    $croute = 0;
                    while ($listen = fgets($router, 1024)) {
                        $listen = preg_replace($pattern, $replace, $listen);

                        if ($listen === "") {
                            continue;
                        }
                        if ($listen === "route:" && $start == 0 && $end === 0) {
                            $start = 1;
                            continue;
                        } elseif ($listen === "endroute" && $start === 1 & $end === 0) {
                            $end = 1;
                            array_push($routingArray, $rtarray);
                        } elseif (($this->strlikeInArray($listen, array("activity", "path", "name")) !== false) ||
                            ($this->strlikeInArray($listen, array("activity", "path",
                                    "name", "visibility")) !== false)) {
                            $listen = explode(':', $listen);
                            $rtarray[$listen[0]] = $listen[1];
                        }

                        if ($start === 1 && $end === 1) {
                            $rtarray = array("method" => "", "path" => "", "name" => "", "visibility" => "private");
                            $start = $end = 0;
                            $croute++;
                        }
                    }
                    $newfilename = str_replace(".merc", "", $file);
                    $view = $this->generateRoute(
                        'iumio_manager_routing_manager_get_one',
                        array("filename" => $newfilename, "appname" => $one->name)
                    );
                    $remove = $this->generateRoute(
                        'iumio_manager_routing_manager_remove_one',
                        array("filename" => $newfilename, "appname" => $one->name)
                    );
                    array_push($routings, array("name" => $file, "count_route" => $croute, "app" => $one->name,
                        'view' => $view, 'remove' => $remove));
                }
            }
        }

        return ($routings);
    }
293185
protected function getInterfaceMethods()
    {
        $methods = array();

        foreach ($this->interfaces as $interface) {
            $ref = new \ReflectionClass($interface);
            $methods = array_merge($methods, $ref->getMethods());
        }

        return $methods;
    }
238947
public function getPostprocessor(): MiddlewareInterface
    {
        if (is_null($this->postProcessor)) {
            if (method_exists($this, 'resolve')) {
                $this->setPostprocessor($this->resolve(Middleware::class));
            } else {
                $this->setPostprocessor(new Middleware());
            }
        }

        return $this->postProcessor;
    }