Create PHPixie request from server request.

If the server request is not specified it will be created
from globals
@param Request\ServerRequest $serverRequest
@return HTTP\Request
3784
public function request($serverRequest = null)
    {
        if ($serverRequest === null) {
            $serverRequest = $this->sapiServerRequest();
        }
        return $this->builder->request($serverRequest);
    }
1133202
public function processServerRequest($serverRequest)
    {
        $response = $this->processor()->process($serverRequest);

        return $response->asResponseMessage(
            $this->builder->context()->httpContext()
        );
    }
856662
public function create(PageRequest $request)
    {

        $page = $this->repository->newInstance([]);
        return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('page::page.name')) 
            ->view('page::page.create', true) 
            ->data(compact('page'))
            ->output();
    }
732102
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        $stack = new Stack(
            $this->handlers,
            $this->handlerResolver
        );
        return $stack->handle($request);
    }
1279326
private function createRequestManager(ServerRequestInterface $request)
    {
        return new Promise(function ($resolve, $reject) use ($request) {
            $bodyStream = '';

            $request->getBody()->on('data', function ($data) use (&$bodyStream, $request) {
                $bodyStream .= $data;
            });
            $request->getBody()->on('end', function () use ($resolve, $request, &$bodyStream) {
                $response = $this->onRequest($request->withBody(new StringStream($bodyStream)));
                $resolve($response);
            });
            $request->getBody()->on('error', function (\Exception $exception) use ($resolve) {
                $response = new ReactResponse(
                    400,
                    ['Content-Type' => 'text/plain'],
                    'An error occured while reading: ' . $exception->getMessage()
                );
                $resolve($response);
            });
        });
    }
787838
public static function createFromServerRequest(ServerRequestInterface $request)
    {
        $data = $request->getCookieParams();
        $cookies = [];
        foreach ($data as $name => $value) {
            $cookies[] = new Cookie($name, $value);
        }

        return new static($cookies);
    }
1007360
private function createContent(ServerRequestInterface $request)
    {
        $route = $request->getAttribute('route');
        $template = $this->viewInflector->inflect($route);
        $this->templateEngine->parse($template);
        return $this->templateEngine->process($request->getAttribute('viewData', []));
    }
93745
public function respond(ServerRequest $request)
    {
        try
        {
            $response = $this->request($request)
                ->finalize()
                ->getResponse();
        }
        catch(\Exception $e)
        {
            if($failRoute = $this->failRoute)
            {
                $response = $this->execute($failRoute, array('exception' => $e, 'request' => $request), $request)
                    ->finalize()
                    ->getResponse();

                $this->failRoute = null;
            }
            else if($this->map->hasFailRoute())
            {
                $response = $this->execute($this->map->getFailRoute(), array('exception' => $e, 'request' => $request), $request)
                    ->finalize()
                    ->getResponse();
            }
            else
            {
                $message = '<pre><h2>['.get_class($e).'] '.$e->getMessage().'</h2>'.PHP_EOL;
                $message .= $e->getTraceAsString();

                $response = Response::createEmptyResponse()
                    ->setStatus(404)
                    ->setBody($message);
            }
        }

        return $response;
    }
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);
    }
1343863
public function createServerRequest(
        string $method,
        $uri,
        array $serverParams = []
    ): ServerRequestInterface{
        if(!is_string($uri) && !is_subclass_of($uri, UriInterface::class)){
            $class  = UriInterface::class;
            throw new \InvalidArgumentException(
                "Second argument must be of the type string or {$class}, " . gettype($uri) . " given."
            );
        }

        return new ServerRequest(
            $method,
            is_string($uri) ? $this->getUriFactory()->createUri($uri) : $uri,
            $serverParams
        );
    }
544448
public static function create(ServerRequestInterface $request)
    {
        $method = strtolower($request->getMethod());
        $query = $request->getQueryParams();
        $post = $request->getParsedBody();

        $input = new PsrInput(array_merge($query, $post));
        $input->setMethod($request->getMethod());

        $filter = $input->getFilter() instanceof NullFilter ? null : $input->getFilter();

        // Sort by importance
        $input->get = new Input($query, $filter);
        $input->post = new Input($method === 'post' ? $post : [], $filter);
        $input->files = new PsrFilesInput($request->getUploadedFiles(), $filter);
        $input->put = new Input($method === 'put' ? $post : [], $filter);
        $input->patch = new Input($method === 'patch' ? $post : [], $filter);
        $input->delete = new Input($method === 'delete' ? $post : [], $filter);
        $input->link = new Input($method === 'link' ? $post : [], $filter);
        $input->unlink = new Input($method === 'unlink' ? $post : [], $filter);
        $input->request = new Input(array_merge($query, $post));

        // Super Globals
        $input->server = new Input($request->getServerParams(), $filter);
        $input->header = new PsrHeaderInput($request->getHeaders(), $filter);
        $input->cookie = new CookieInput($request->getCookieParams(), $filter);

        return $input;
    }
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);
    }
428558
public function create(ServerRequestInterface $request, Route $route)
    {
        $this->uriGenerator->setRequest($request);
        return new Context($request, $route, $this->uriGenerator);
    }
853992
protected function reviveRequest(ServerRequestInterface $request)
    {
        $isStale = interface_exists('Jasny\HttpMessage\GlobalEnvironmentInterface') &&
            $request instanceof GlobalEnvironmentInterface &&
            $request->isStale();
        
        return $isStale ? $request->revive() : $request;
    }
1018845
public function createServerRequestFromArray(array $server)
    {
        return new ServerRequest(
            $server['REQUEST_METHOD'] ?? 'GET', 
            $server['REQUEST_URI'], 
            $this->getHeadersFromServerArr($server),
            null,
            $server['SERVER_PROTOCOL'] ?? 'HTTP/1.1',
            $server
        );
    }
1322203
public function webhook(?ServerRequestInterface $request = null): Webhook
    {
        return new Webhook($this->appSecret, $this->verifyToken, $this->pageToken, $this->client, $request);
    }
47554
protected function _addTokenToRequest($token, ServerRequest $request)
    {
        $params = $request->getAttribute('params');
        $params['_csrfToken'] = $token;

        return $request->withAttribute('params', $params);
    }