Environment::handle

Handles a request and produces a response

May call other collaborating code to generate the response.

@param \O2System\Psr\Http\Message\ServerRequestInterface $request
557757
public function handle(ServerRequestInterface $request)
    {
        if (null !== ($ssid = input()->get('ssid')) && services()->has('user')) {
            if (services()->get('user')->validate($ssid)) {
                set_cookie('ssid', $ssid);

                echo services()->get('user')->getIframeScript();
                exit(EXIT_SUCCESS);
            }
        }
    }
752675
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        //Session name
        if ($this->name) {
            $name = $this->name;
            $this->session->setName($name);
        } else {
            $name = $this->session->getName();
        }

        $this->session->start($this->options);

        $response = $handler->handle($request);

        if ($this->session->isStarted() && ($this->session->getName() === $name)) {
            $this->session->commit();
        }

        return $response;
    }
540567
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        $allowLayers = $this->store->getLayersForRequest($request);
        $this->runner->setLayers($allowLayers);

        $this->emit(self::EVENT_BEFORE_HANDLE, [$request, $allowLayers]);
        $response = $this->runner->handle($request);
		$this->emit(self::EVENT_AFTER_HANDLE, [$request, $allowLayers, $response]);

		return $response;
    }
249343
public function handle(ServerRequestInterface $request, Response $response)
    {
        $server = $request->getServerParams();
        $server['REQUEST_METHOD'] = $request->getMethod();
        $server['REQUEST_URI'] = $request->getUri()->getPath();
        $globals = [
            '_GET' => $request->getQueryParams(),
            '_POST' => $request->getParsedBody()
        ];
        $req = $this->router->match($globals, $server);
        $resourceObject = $this->resource->{$req->method}->uri($req->path)->withQuery($req->query)->eager->request();
        $response = $this->toPsr7Response($response, $resourceObject);

        return $response;
    }
1152398
public function handle(ServerRequestInterface $request)
    {
        $clientIpAddress = $request->getClientIpAddress();
        $debugIpAddresses = config('ipAddresses')->offsetGet('debug');

        if (in_array($clientIpAddress, $debugIpAddresses)) {
            $_ENV[ 'DEBUG_STAGE' ] = 'DEVELOPER';

            error_reporting(-1);
            ini_set('display_errors', 1);

            if (isset($_REQUEST[ 'PHP_INFO' ])) {
                phpinfo();
                exit(EXIT_SUCCESS);
            }
        } else {
            ini_set('display_errors', 0);
            error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
        }
    }
1012360
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        if(isset($this->middlewares[$this->index]))
        {
            $middleware = $this->middlewares[$this->index];
            if($middleware instanceof RequestHandlerInterface)
            {
                $requestHandler = $middleware;
            }
            else
            {
                $requestHandler = RequestContext::getServerBean($middleware);
            }
        }
        else
        {
            return RequestContext::get('response');
        }
        return $requestHandler->process($request, $this->next());
    }
838615
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $result = $this->router->dispatch(
            $request->getMethod(),
            $request->getUri()->getPath()
        );

        return $handler->handle(
            $request->withAttribute('routing', $result)
        );
    }
35233
protected function handleRequest(ServerRequestInterface $request)
    {
        if ($this->getStaticDirectory()) {
            $staticResponse = $this->serveStatic($request);
            if ($staticResponse instanceof ResponseInterface) {
                return $staticResponse;
            }
        }

        if ($bridge = $this->getBridge()) {
            try {
                $response = $bridge->handle($request);
            } catch (\Throwable $t) {
                error_log(
                    'An exception was thrown by the bridge. Forcing restart of the worker. The exception was: ' .
                    (string)$t
                );
                $response = new Response(500, [], 'Unexpected error');

                @ob_end_clean();
                $this->shutdown();
            }
            $this->sendCurrentFiles();
        } else {
            $response = new Response(404, [], 'No Bridge defined');
        }

        if (headers_sent()) {
            //when a script sent headers the cgi process needs to die because the second request
            //trying to send headers again will fail (headers already sent fatal). Its best to not even
            //try to send headers because this break the whole approach of php-pm using php-cgi.
            error_log(
                'Headers have been sent, but not redirected to client. Forcing restart of the worker. ' .
                'Make sure your application does not send headers on its own.'
            );
            $this->shutdown();
        }
        $this->sendMessage($this->controller, 'stats', ['memory_usage' => round(memory_get_peak_usage(true)/1048576, 2)]); // Convert memory usage to MB
        return $response;
    }
55461
public function dispatch(ServerRequest $request = null)
    {
        $response = $this->respond($request ? : $this->request);

        $response->send();
    }
767154
public function handle($request)
	{
		try
		{
			$response = $this->sendRequestThroughRouter($request);
		}
		catch (Exception $e)
		{
			$this->reportException($e);

			$response = $this->renderException($request, $e);
		}

		$this->app['events']->fire('kernel.handled', [$request, $response]);

		return $response;
	}
958907
public function handle(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
    {
        $type = 'psr-7';
        $this->cors->setRequest($type, $request);
        $this->cors->setResponse($type, $response);
        $this->cors->handle();

        return $this->cors->getResponse();
    }
892227
protected function handle(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
    {
        $cors = $this->cors->getCors();
        $cors->setRequest('psr-7', $request);
        $cors->setResponse('psr-7', $response);
        $cors->handle();

        return $cors->getResponse();
    }
530849
public function handle(ServerRequestInterface $request, DelegateInterface $next)
    {
        $cookies = $request->getCookieParams();

        if (!isset($cookies[static::SESSION_ID_KEY])) {
            $sessionId = session_create_id();
        } else {
            $sessionId = $cookies[static::SESSION_ID_KEY];
        }

        $request->withHeader(static::SESSION_ID_KEY, $sessionId);

        $response = $next->process($request);

        return $response->withCookie(static::SESSION_ID_KEY, $sessionId);
    }
1014461
public function dispatch(ServerRequestInterface $request): ResponseInterface
    {
        $resolved = $this->resolve(0);

        return $resolved->handle($request);
    }
338544
public function handle(
        ServerRequestInterface $request, ResponseInterface $response
    )
    {
        $path = array_key_exists(self::QUERY_PARAM, $request->getQueryParams())
            ? $request->getQueryParams()[self::QUERY_PARAM]
            : '';
        $uri = Uri::create($request->getUri());
        $queryString = ltrim(
            str_replace(
                self::QUERY_PARAM."={$path}",
                '',
                $uri->getQuery()
            ),
            '&'
        );
        $uri = $uri->withPath(str_replace('//', '/', "/$path"))
            ->withQuery($queryString);
        /** @var ServerRequestInterface $request */
        $request = $request->withUri($uri);
        return $this->executeNext($request, $response);
    }
86826
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $frontendController = $GLOBALS['TSFE'];
        if (!$frontendController->isGeneratePage() || !isset($request->getQueryParams()[self::argumentNamespace])) {
            return $handler->handle($request);
        }
        $this->ensureRequiredEnvironment();

        $frontendController->config['config']['disableAllHeaderCode'] = 1;
        $frontendController->pSetup = [
            '10' => 'TYPOSCRIPT_RENDERING',
            '10.' => [
                'request' => $request->getQueryParams()[self::argumentNamespace],
            ],
        ];

        return $handler->handle($request);
    }
1068465
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        $body = $request->getParsedBody();

        $method = strtoupper($body[self::METHOD_INPUT_KEY] ?? $request->getMethod());

        $request = $request->withMethod($method);

        $this->match = $this->adapter->match($request);

        return $this->match->handle($request);
    }