Launch route stack
@param  array    $stack
@param  Request  $request
@param  Response $response
@return void
975328
protected function runStack(array $stack, Request $request, Response $response)
    {
        $stack[] = function () use ($response) {
            $response->end();
        };

        $finalStack = array_merge($this->middlewares, $stack);
        $this->waterfall($finalStack, [$request, $response]);
    }
715586
public function dispatchRequest(Request $request, Response $response, Table $table)
    {
        $pathInfo = $request->server["path_info"] ?? "/";
        $routes = $this->settings["routes"];
        $actionClass = $routes[$pathInfo] ?? false;

        try {

            foreach ($this->requestMiddleware as $middleware) {
                $middleware->before($request, $response, $this->settings, $table);
            }

            try {
                /** @var ActionInterface $classObject */
                $classObject = $this->container->get($actionClass);
                $actionResponse = $classObject->__invoke($request, $response, $this->settings, $table);
            } catch (\Throwable $exception) {
                $actionResponse = new ActionResponse(json_encode(["message" => $exception->getMessage()]));
                $actionResponse->setStatusCode(500);
            }

            foreach ($this->requestMiddleware as $middleware) {
                $middleware->after($request, $response, $this->settings, $table, $actionResponse);
            }

        } catch (\Throwable $exception) {
            $actionResponse = new ActionResponse(json_encode(["message" => $exception->getMessage()]));
            $actionResponse->setStatusCode(500);
        }

        $response->status($actionResponse->getStatusCode());
        $response->header("Content-Type", $actionResponse->getContentType());

        $contentBlocks = str_split($actionResponse->getBody(), 2046 * 1024);
        foreach ($contentBlocks as $block) {
            $response->write($block);
        }
        $response->end();
    }
1157045
public function run(ServerRequestInterface $request, ResponseInterface $response)
    {
        $route = $request->getAttribute('route');        
        $name = !empty($route->controller) ? $route->controller : 'default';
        
        try {
            $controller = call_user_func($this->getFactory(), $name);
        } catch (\Exception $ex) {
            trigger_error($ex->getMessage(), E_USER_NOTICE);
            return $this->notFound($request, $response);
        }

        if (!method_exists($controller, '__invoke')) {
            $class = get_class($controller);
            trigger_error("Can't route to controller '$class': class does not have '__invoke' method", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }
        
        return $controller($request, $response);
    }
142418
public function startAction(Request $request)
    {
        $data = json_decode($request->getContent(), true);

        $publicFile = $this->om->getObject($data['file'], PublicFile::class) ?? new PublicFile();

        $this->container->get('claroline.manager.api_manager')->import(
            $publicFile,
            $data['action'],
            $this->getLogFile($request)
        );

        //the following line doesn't work on our live server but it's supposed to be the proper way to do it
        //$this->async->run('claroline:api:load '.$publicFile->getId().' '.$data['action'].' '.$this->getLogFile($request));

        return new JsonResponse('started', 200);
    }
211898
function (start, step) {
    this.step = step || 1;
    this.last = (utils.isUndefined(start) ? 1 : start) - this.step;
    this.stack = [];
}
464082
public function resolve(Request $request, Response $response)
    {
        // Ensure to put *route* in before ;) - here.
        $route  = $request->getAttribute('route');
        $target = $route->getPresenter();

        $this
            ->response($response)
            ->route($route)
            ->className($target)
            ->action($route->getAction())
            ->initMvp($target, $this->getRegistry(), $request);

        return $this->run();
    }
431230
protected static function _merge($stack, &$return)
    {
        while (!empty($stack)) {
            foreach ($stack as $curKey => &$curMerge) {
                foreach ($curMerge[0] as $key => &$val) {
                    $isArray = is_array($curMerge[1]);
                    if ($isArray && !empty($curMerge[1][$key]) && (array)$curMerge[1][$key] === $curMerge[1][$key] && (array)$val === $val) {
                        // Recurse into the current merge data as it is an array.
                        $stack[] = [&$val, &$curMerge[1][$key]];
                    } elseif ((int)$key === $key && $isArray && isset($curMerge[1][$key])) {
                        $curMerge[1][] = $val;
                    } else {
                        $curMerge[1][$key] = $val;
                    }
                }
                unset($stack[$curKey]);
            }
            unset($curMerge);
        }
    }
603033
public function add(Request $request)
    {
        $this->stack = array_slice($this->stack, 0, $this->position + 1);
        $this->stack[] = clone $request;
        $this->position = count($this->stack) - 1;
    }
513868
public function startAuthentication(Request $request, Response $response)
    {
        $response->setStatus(401);
        $response->setHeader('WWW-Authenticate', 'Basic realm="' . (isset($this->options['realm']) ? $this->options['realm'] : sha1(FLOW_PATH_ROOT)) . '"');
        $response->setContent('Authorization required');
    }
1283086
public function run(Request $request = null)
    {
        if (null === $request) {
            $request = Request::createFromGlobals();
        }

        $this->registerMiddleware('Phprest\Middleware\ApiVersion');

        $app = $this->stackBuilder->resolve($this);

        $response = $app->handle($request, self::MASTER_REQUEST, false);
        $response->send();

        $app->terminate($request, $response);
    }
435925
private function matchRoutes(Request $request, Response $response)
    {
        $stack  = [];
        $path   = $request->httpRequest->getPath();
        $method = $request->httpRequest->getMethod();

        foreach ($this->routes as $route) {
            if (!$route->match($path, $method)) {
                continue;
            }

            $methodArgs = $route->getArgs($path);
            $request->setData($methodArgs);

            $route->on('error', function (...$args) {
                $this->emit('error', $args);
            });

            $stack[] = function (...$params) use ($route) {
                $route->run(...$params);
            };
        }

        if (count($stack) == 0) {
            $this->emit('NotFound', array($request, $response));
            return;
        }

        $this->runStack($stack, $request, $response);
    }
469934
public function execute(Framework $framework, WebRequest $request, Response $response)
    {
        // Prepare the page
        $this->setTitle($this->translate('Group management', '\\Zepi\\Web\\AccessControl'));
        $this->activateMenuEntry('group-administration');
        
        // Generate the Table
        $groupTable = new \Zepi\Web\AccessControl\Table\GroupTable(
            $framework, 
            true,
            true
        );
        
        // Displays the group table
        $response->setOutput($this->render('\\Zepi\\Web\\AccessControl\\Templates\\Administration\\Groups', array(
            'groupTable' => $groupTable,
            'tableRenderer' => $this->getTableRenderer()
        )));
    }
343653
public function terminate($request, $response)
    {
        $middlewares = array_merge(
            $this->gatherRouteMiddlewares($request),
            $this->middleware
        );

        foreach ($middlewares as $middleware) {
            list($name, $parameters) = $this->parseMiddleware($middleware);

            $instance = $this->app->make($name);

            if (method_exists($instance, 'terminate')) {
                $instance->terminate($request, $response);
            }
        }

        //$this->app->terminate();
    }
428053
private function executePassiveActions(Request $request, Response $response): Response
    {
        foreach ($this->getRouter()->getConfiguration()->getPassiveActions() as $action => $whitelist) {
            $activeAction = $this->getRouter()->getActionAlias($request);

            if (!in_array($activeAction, $whitelist) && !in_array('all', $whitelist)) {
                continue;
            }

            if (in_array('-' . $activeAction, $whitelist) && in_array('all', $whitelist)) {
                continue;
            }

            $route = $this->getRouter()->getAliasedRoute($action, [], Router::PASSIVE_ACTION);

            if (!method_exists($route->getController(), $route->getAction())) {
                throw new ActionNotFoundException($action . ' passive action is present in registry, but can\'t be found or is improperly configured.');
            }

            $controllerName = $route->getController();
            $controller = new $controllerName($this->drivers, $request, $response);
            $response = $controller->{$route->getAction()}(...$route->getActionParams());
        }

        return $response;
    }
677347
static public function dispatch($render = true, \Lollipop\HTTP\Request $response = null, \Lollipop\HTTP\Response $request = null) {
        if (is_null($response)) {
            // Create a new response
            $response = new Response();
        }
        
        if (is_null($request)) {
            // New request object
            $request = new Request();
        }

        // Get URL Path property only
        $url = trim($request->url(PHP_URL_PATH), '/');
        
        // Create an instance of URL parser for checking if current
        // path matches any route
        $parser = new \Lollipop\HTTP\URL\Pretty($url);
        
        // Get 404 Page Not Found
        // Check if `404` route was declared
        self::$_active_route = isset(self::$_stored_routes[$request->method()]['404']) ?
            self::$_stored_routes[$request->method()]['404'] :
            self::_getDefaultPageNotFound();
        
        foreach (self::$_stored_routes[$request->method()] as $path => $route) {
            if ($parser->test($path)) {
                // Set the route arguments based from the matches from the url
                $route['arguments'] = $parser->getMatches();;

                // Set route as active
                self::$_active_route = $route;
            }
        }
        
        // Stack specific route level middleware
        if (isset(self::$_active_route['middlewares']) && is_array(self::$_active_route['middlewares'])) {
            foreach (self::$_active_route['middlewares'] as $mw) {
                self::_stackMiddleware($mw);
            }
        }
        
        // Stack route level middleware
        if (isset(self::$_middlewares) && is_array(self::$_middlewares)) {
            foreach (self::$_middlewares as $mw) {
                self::_stackMiddleware($mw);
            }
        }
        
        // Now call the main callback
        $response = self::_process($request, $response);
        
        // Render output from our application
        if (!($response instanceof Response)) {
            $response = new Response($response);
        }
        
        // Is gzip compression enabled in config
        if (Config::get('output.compression')) {
            $response->compress();
        }

        if ($render) {
            // `->render()` will set cookies, header and document
            // content
            $response->render();
        }

        return $response;
    }
1214035
public function runRouteWithinStack(Request $request)
    {
        return (new Pipeline($this->container))
            ->send($request)
            ->through([$this->middleware])
            ->run();
    }
195256
public function push(HandlerStack $stack)
    {
        $stack->push(Middleware::mapRequest(function (RequestInterface $request) {
            $this->initEvent($request);

            return $request;
        }), 'eventDispatcher_initEvent');

        $stack->push(function (callable $handler) {
            return function (
                RequestInterface $request,
                array $options
            ) use ($handler) {
                $promise = $handler($request, $options);

                return $promise->then(
                    function (ResponseInterface $response) use ($request) {
                        $this->sendEvent($request, $response);

                        return $response;
                    },
                    function (\Exception $reason) use ($request) {
                        $this->sendErrorEvent($request, $reason);

                        throw $reason;
                    }
                );
            };
        }, 'eventDispatcher_dispatch');

        return $stack;
    }