@param ServerRequestInterface $request

@return \Psr\Http\Message\ResponseInterface
554109
public function handle(ServerRequestInterface $request)
    {
        $userId = array_get($request->getQueryParams(), 'id');

        $testCheck = new Ip(User::find($userId));
        $testCheck->run();

        return json_encode($testCheck->getReport());
    }
939406
protected function generate404(ServerRequestInterface $request): ResponseInterface
    {
        if ($this->default404 !== null) {
            if (\is_callable($this->default404)) {
                return \call_user_func_array($this->default404, [$request, [$this, 'handle']]);
            } elseif ($this->default404 instanceof MiddlewareInterface) {
                return $this->default404->process($request, $this);
            } elseif (\is_string($this->default404)) {
                $default404Instance = (new $this->default404());
                if (\method_exists($default404Instance, 'process')) {
                    return $default404Instance->process($request, $this);
                }
            }

            throw new RouterException('The default404 is invalid');
        }
        throw new RouterException('No route found to dispatch');
    }
136158
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        /**
         * If request is modified by a middleware, and as ServerRequestInterface is immutable, given $request must
         * replace current ServerRequestInterface in RequestHandler PSR-11 container.
         */
        $this->container->set("request", $request);

        $middlewareEntry = current($this->middlewareSequence);
        next($this->middlewareSequence);

        // If middleware sequence is exhausted, controller is instantiated and run.
        if ($middlewareEntry === false) {

            /**
             * @var Route $route
             */
            $route = $this->container->get("route");

            $controllerData = explode("::", $route->controller);
            if (count($controllerData) !== 2) {

                throw new RuntimeException("Invalid controller declaration for route {$route->name} (expecting '\\Namespace\\Class::method' format)");

            }

            $controllerClass = $controllerData[0];
            if (class_exists($controllerClass) === false) {

                throw new RuntimeException("Invalid controller declaration for route {$route->name} (unknown class {$controllerClass})");

            }

            /**
             * @var $controller AbstractController
             */
            $controller = new $controllerClass($this->container);

            $controllerMethod = $controllerData[1];
            if (method_exists($controller, $controllerMethod) === false) {

                throw new BadMethodCallException("{$controllerClass}::{$controllerMethod} declared in routes doesn't exists in {$controllerClass}");

            }

            /**
             * @var $response ResponseInterface
             */
            $response = $controller->{$controllerMethod}();
            if (($response instanceof ResponseInterface) === false) {

                throw new LogicException("Method {$controllerMethod} must return an instance of PSR-7 ResponseInterface");

            }

            return $response;

        } else {

            $middlewareFQCN = is_array($middlewareEntry) ? $middlewareEntry[0] : $middlewareEntry;
            $middlewareParams = is_array($middlewareEntry) && count($middlewareEntry) > 1 ? $middlewareEntry[1] : null;

            /**
             * @var $middleware MiddlewareInterface
             */
            $middleware = new $middlewareFQCN($middlewareParams);
            if (($middleware instanceof MiddlewareInterface) === false) {

                throw new LogicException("Middleware {$middlewareFQCN} must implements PSR-11 MiddlewareInterface");

            }

            return $middleware->process($request, $this);

        }
    }
1286897
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        //die(var_dump($this->getRouter()->getRoutes()));
        //die(var_dump($this->getRouter()->relativePathFor('test111', ['id' => '0123456'])));

        //die(var_dump($request->getServerParam('HTTP_HOST')));

        // apply PHP config settings.
        //$this->boot();

        // TODO : c'est plutot ici qu'on devrait la request::fromGlobals et éventuellement la mettre dans le container, non ????, avec éventuellement la possibilité de lui passer une request en paramétre de la méthode Run($request) et donc on créé la request ou on utilisera celle passée en paramétre. Celka peut servir si un utilisateur créé sa request avant (dans le cas ou il utilise du PSR7 request), mais aussi servir pour nos tests PHPUNIT avec une request pré-initilalisée. Cela peut aussi permettre à l'utilisateur de modifier la request, genre pour un sanitize, ou alors pour changer le type de méthode si il y a un champ formulaire hidden _method pour faire un override de la méthode http.

        // create response
        /*
        $headers = new Headers(['Content-Type' => 'text/html; charset=UTF-8']);
        $httpVersion = $this->getSetting('httpVersion');
        $response = new Response(200, $headers);
        $response = $response->withProtocolVersion($httpVersion);
        */

        $responseFactory = $this->kernel->get(ResponseFactoryInterface::class);
        $emptyResponse = $responseFactory->createResponse(204);

        $this->pipeline->pipe($this->router->getMiddlewareStack());
        // add an empty response as default response if no route found and no 404 handler is added.
        //array_push($this->middlewares, $emptyResponse);
        $this->pipeline->pipe($emptyResponse);

        $response = $this->pipeline->handle($request);

        return $response;

        //'text/plain; q=0.5, application/json; version=1.0, application/xml; version=2.0;'
//'text/plain;q=0.5,text/html,text/*;q=0.1'

/*
        $request = $request->withHeader('Accept','text/plain; q=0.5, application/json; version=1.0, application/xml; version=2.0;');
        die(print_r($request->getAcceptableContentTypes()));

        $request = $request->withHeader('Accept-Language', 'fr;q=0.9, fr-CH, en;q=0.7, de;q=0.8, *;q=0.5');
        die(print_r($request->getAcceptableLanguages()));
*/

/*
      if ($response->isSuccessful() && $this->requestIsConditional()) {
            if (! $response->headers->has('ETag')) {
                $response->setEtag(md5($response->getContent()));
            }
            $response->isNotModified($request);
        }
*/
    }
1086915
public function create(ServerRequestInterface $request): ResponseInterface
    {
        $tree_name  = $request->get('tree_name', '');
        $tree_title = $request->get('tree_title', '');

        // We use the tree name as a file name, so no directory separators allowed.
        $tree_name = basename($tree_name);

        if (Tree::findByName($tree_name)) {
            FlashMessages::addMessage(I18N::translate('The family tree “%s” already exists.', e($tree_name)), 'danger');

            $url = route('admin-trees');
        } else {
            $tree = Tree::create($tree_name, $tree_title);
            FlashMessages::addMessage(I18N::translate('The family tree “%s” has been created.', e($tree->name())), 'success');

            $url = route('admin-trees', ['ged' => $tree->name()]);
        }

        return redirect($url);
    }
1014203
public function dispatchRequest(ServerRequestInterface $request) : ResponseInterface
    {
        $match = $this->dispatch($request->getMethod(), $request->getUri()->getPath());

        switch ($match[0]) {
            case FastRoute::NOT_FOUND:
                $this->setNotFoundDecoratorMiddleware();
                break;
            case FastRoute::METHOD_NOT_ALLOWED:
                $allowed = (array) $match[1];
                $this->setMethodNotAllowedDecoratorMiddleware($allowed);
                break;
            case FastRoute::FOUND:
                $match[1]->setVars($match[2]);
                $this->setFoundMiddleware($match[1]);
                break;
        }

        return $this->handle($request);
    }
1009634
public function wizard(ServerRequestInterface $request): ResponseInterface
    {
        $continue = $request->getQueryParams()['continue'] ?? '';

        $title = I18N::translate('Upgrade wizard');

        if ($continue === '1') {
            return $this->viewResponse('admin/upgrade/steps', [
                'steps' => $this->wizardSteps(),
                'title' => $title,
            ]);
        }

        return $this->viewResponse('admin/upgrade/wizard', [
            'current_version' => Webtrees::VERSION,
            'latest_version'  => $this->upgrade_service->latestVersion(),
            'title'           => $title,
        ]);
    }
353341
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        if (false === $this->booted) {
            $this->boot();
        }

        try {
            return $this->pipe->handle($request);
        } catch (Exception $e) {
            $this->getContainer()->get('logger')->error($e);
        }
    }
1293086
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        if (!isset($this->middlewaresInPipe[$this->currentMiddlewareInPipeIndex])) {
            return $this->generate404($request);
        }

        $middleware = $this->getMiddlewareInPipe();
        if (\is_callable($middleware)) {
            return \call_user_func_array($middleware, [$request, [$this, 'handle']]);
        } elseif ($middleware instanceof MiddlewareInterface) {
            return $middleware->process($request, $this);
        } elseif (\is_string($middleware)) {
            $middlewareInstance = (new $middleware());
            if (\method_exists($middlewareInstance, 'process')) {
                return $middlewareInstance->process($request, $this);
            }
        } elseif ($middleware instanceof self) {
            if ($middleware->findRouteRequest($request)) {
                return $middleware->dispatch($request);
            }

            return $this->handle($request);
        }
        throw new RouterException(\sprintf('Middleware is invalid: %s', \gettype($middleware)));
    }
719944
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        if (empty($this->requestHandler)) {
            $this->requestHandler = $this->requestHandler();
        }

        return $this->pipeline->process(
            $request->withAttribute(self::ROUTE_ATTRIBUTE, $this),
            $this->requestHandler
        );
    }
53043
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        try {
            $route = $this->matchRoute($request);
        } catch (RouteException $e) {
            throw new RouterException("Invalid route definition", $e->getCode(), $e);
        }

        if (empty($route)) {
            throw new RouteNotFoundException($request->getUri());
        }

        return $this->container->get(ScopeInterface::class)->runScope(
            [RouteInterface::class => $route],
            function () use ($route, $request) {
                return $route->handle($request);
            }
        );
    }
363264
private function generateNotFoundPlainResponse(ServerRequestInterface $request) : ResponseInterface
    {
        $response = ($this->responseFactory)()->withStatus(StatusCodeInterface::STATUS_NOT_FOUND);
        $response->getBody()
            ->write(\sprintf(
                "Encountered a 404 Error, %s doesn't exist",
                (string) $request->getUri()
            ));

        return $response;
    }
1367020
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        $user_id = (int) $request->getParsedBody()['user_id'];

        $user = $this->user_service->find($user_id);

        if ($user === null) {
            throw new NotFoundHttpException('User ID ' . $user_id . ' not found');
        }

        if ($this->user->id() !== $user_id) {
            Log::addAuthenticationLog('Masquerade as user: ' . $user->userName());
            Auth::login($user);
            Session::put('masquerade', '1');
        }

        return response('', StatusCodeInterface::STATUS_NO_CONTENT);
    }
669300
public function doRequest(HttpRequestInterface $request)
    {
        $responseClass = $this->responseClass;

        /** @var HttpResponseInterface $responseObject */
        $responseObject = new $responseClass();

        return $responseObject->build($request);
    }
1195658
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        return $this->middleware->process($request, $this->delegate);
    }
1120293
public static function fromPsrRequest(ServerRequestInterface $request)
    {
        $url = (string) $request->getUri();
        $httpMethod = $request->getMethod();

        // Let's find the parameters relevant to this request
        $parameters = (array) $request->getParsedBody() + $request->getQueryParams();

        // We have a Authorization-header with OAuth data. Parse the header
        // and add those overriding any duplicates from GET or POST
        if (substr($request->getHeaderLine('Authorization'), 0, 6) == 'OAuth ') {
            $header_parameters = Util::splitHeader(
                $request->getHeaderLine('Authorization')
            );
            $parameters = array_merge($parameters, $header_parameters);
        }

        return new Request($httpMethod, $url, $parameters);
    }
1252094
public function onRequest(ServerRequestInterface $request)
    {
        if ($this->isPopulateServer()) {
            $this->prepareEnvironment($request);
        }

        $remoteIp = $request->getHeaderLine('X-PHP-PM-Remote-IP');
        $remotePort = $request->getHeaderLine('X-PHP-PM-Remote-Port');

        $request = $request->withoutHeader('X-PHP-PM-Remote-IP');
        $request = $request->withoutHeader('X-PHP-PM-Remote-Port');

        $request = $request->withAttribute('remote_address', $remoteIp);
        $request = $request->withAttribute('remote_port', $remotePort);

        $logTime = date('d/M/Y:H:i:s O');

        $catchLog = function ($e) {
            console_log((string) $e);
            return new Response(500);
        };

        try {
            $response = $this->handleRequest($request);
        } catch (\Throwable $t) {
            $response = $catchLog($t);
        }

        $promise = new Promise(function ($resolve) use ($response) {
            return $resolve($response);
        });

        $promise = $promise->then(function (ResponseInterface $response) use ($request, $logTime, $remoteIp) {
            if ($this->isLogging()) {
                $this->logResponse($request, $response, $logTime, $remoteIp);
            }
            return $response;
        });

        return $promise;
    }