@param string                      $index
@param UriInterface                $requestUri
@param JsonApiQueryParserInterface $queryParser
@param CrudInterface               $crud
@param EncoderInterface            $encoder

@return ResponseInterface
547369
protected static function defaultDeleteHandler(
        string $index,
        UriInterface $requestUri,
        JsonApiQueryParserInterface $queryParser,
        CrudInterface $crud,
        EncoderInterface $encoder
    ): ResponseInterface {
        $validatedIndex = (string)$queryParser->parse($index)->getIdentity();
        $crud->remove($validatedIndex);

        $responses = static::defaultCreateResponses($requestUri, $encoder);
        $response  = $responses->getCodeResponse(204);

        return $response;
    }
172322
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        if ($this->checkRequest($request)) {
            $response = $handler->handle($request);
            $version = $request->getAttribute('ncryptf-version');
            $publicKey = $request->getAttribute('ncryptf-request-public-key');
            $token = $request->getAttribute('ncryptf-token');
            
            if ($version === null || $publicKey === null) {
                return $response->withStatus(400, 'Unable to encrypt request.');
            }

            $stream = $response->getBody();
            $class = $this->key;
            $key = $class::generate();
            
            $this->cache->set(
                $key->getHashIdentifier(),
                \function_exists('igbinary_serialize') ? \igbinary_serialize($key) : \serialize($key)
            );

            $r = new Request(
                $key->getBoxSecretKey(),
                $token === null ? $key->getSignSecretKey() : $token->signature
            );

            $content = $r->encrypt(
                (string)$stream,
                $publicKey,
                $version,
                $version === 2 ? null : \random_bytes(SODIUM_CRYPTO_BOX_NONCEBYTES)
            );

            if ($version === 1) {
                $response = $response->withHeader('x-sigpubkey', \base64_encode($token === null ? $key->getSignPublicKey() : $token->getSignaturePublicKey()))
                    ->withHeader('x-signature', \base64_encode($r->sign((string)$stream)))
                    ->withHeader('x-nonce', \base64_encode($r->getNonce()))
                    ->withHeader('x-pubkey', \base64_encode($key->getBoxPublicKey()));
            }

            $stream->rewind();
            $stream->write(\base64_encode($content));
            return $response->withBody($stream)
                ->withHeader('Content-Type', 'application/vnd.ncryptf+json')
                ->withHeader('x-public-key-expiration', $key->getPublicKeyExpiration())
                ->withHeader('x-hashid', $key->getHashIdentifier());
        }

        return $handler->handle($request)
            ->withHeader('Content-Type', 'application/vnd.ncryptf+json');
    }
370626
public function getUriSegment($index)
    {
        $segments = explode('/', $this->server->get('REQUEST_URI'));
        if (isset($segments[$index])) {
            return $segments[$index];
        }
        return false;
    }
554023
protected function buildRequestQueryInterpreter(
            Interpretations\IRequestInterpretation $requestInterpretation,
            IScopeInterpreter $scopeInterpreter,
            O\IEvaluationContext $evaluationContext = null
    ) {
        return new RequestQueryInterpreter($requestInterpretation, $scopeInterpreter, $evaluationContext);
    }
442057
private function processBeginRequestRecord(int $requestId, ?string $contentData): void
    {
        if (isset($this->requests[$requestId])) {
            throw new ProtocolException('Unexpected FCGI_BEGIN_REQUEST record');
        }

        $contentFormat = 'nrole/Cflags/x5';

        $content = unpack($contentFormat, $contentData);

        $keepAlive = DaemonInterface::FCGI_KEEP_CONNECTION & $content['flags'];

        $this->requests[$requestId] = [
            'keepAlive' => $keepAlive,
            'stdin'     => fopen('php://temp', 'r+'),
            'params'    => [],
        ];

        if ($this->shutdown) {
            $this->endRequest($requestId, 0, DaemonInterface::FCGI_OVERLOADED);

            return;
        }

        if (DaemonInterface::FCGI_RESPONDER !== $content['role']) {
            $this->endRequest($requestId, 0, DaemonInterface::FCGI_UNKNOWN_ROLE);

            return;
        }
    }
99712
function queryController(requestUri) {
    try {
        if (requestUri === undefined)
            return null;
        //split path
        var segments = requestUri.pathname.split('/');
        //put an exception for root controller
        //maybe this is unnecessary exception but we need to search for root controller e.g. /index.html, /about.html
        if (segments.length === 2)
            return 'root';
        else
        //e.g /pages/about where segments are ['','pages','about']
        //and the controller of course is always the second segment.
            return segments[1];
    }
    catch (err) {
        throw err;
    }
}
377120
private function createHttpRequest(IndexQueryRequest $getRequest)
    {
        $request = $this->createRequest($getRequest);
        $query   = $request->getQuery();

        $request->setHeader('Accept', 'application/json');
        $query->add('stream', 'true');

        if ($getRequest->returnTerms !== null) {
            $query->add('return_terms', $getRequest->returnTerms ? 'true' : 'false');
        }

        if ($getRequest->termRegex !== null) {
            $query->add('term_regex', $getRequest->termRegex);
        }

        if ($getRequest->maxResults !== null) {
            $query->add('max_results', $getRequest->maxResults);
        }

        if ($getRequest->continuation !== null) {
            $query->add('continuation', $getRequest->continuation);
        }

        if ($getRequest->paginationSort !== null) {
            $query->add('pagination_sort', $getRequest->paginationSort);
        }

        if ($getRequest->timeout !== null) {
            $query->add('timeout', $getRequest->timeout);
        }

        return $request;
    }
766495
public function decryptRequestWithSharedKey(
        RequestInterface $request,
        SharedEncryptionKey $key
    ): RequestInterface {
        $encrypted = Base64UrlSafe::decode((string) $request->getBody());
        return $request->withBody(
            $this->adapter->stringToStream(
                Simple::decrypt($encrypted, $key)
            )
        );
    }
483579
public final function withUri(
       UriInterface $uri,
       $preserveHost = false): RequestInterface
   {
       if (true === $preserveHost
        && !array_key_exists("Host", $this->header)
        && $uri->getHost()) {
           return $this->with("uri", $uri)->withHeader("Host", $uri->getHost());
       }
       return $this->with("uri", $uri);
   }
734765
public function requestServerData($uri, $postData = [])
    {
        $result = Http::post($this->createServerUrl($uri), function ($http) use ($postData) {
            $this->applyHttpAttributes($http, $postData);
        });

        if ($result->code == 404) {
            throw new ApplicationException(Lang::get('system::lang.server.response_not_found'));
        }

        if ($result->code != 200) {
            throw new ApplicationException(
                strlen($result->body)
                ? $result->body
                : Lang::get('system::lang.server.response_empty')
            );
        }

        $resultData = false;

        try {
            $resultData = @json_decode($result->body, true);
        }
        catch (Exception $ex) {
            throw new ApplicationException(Lang::get('system::lang.server.response_invalid'));
        }

        if ($resultData === false || (is_string($resultData) && !strlen($resultData))) {
            throw new ApplicationException(Lang::get('system::lang.server.response_invalid'));
        }

        return $resultData;
    }
285786
private function getRoutesFromIndex (&$routes, &$routesIndex, &$requestMethod, &$requestPathParts, $requestPathIndex = 0) {
        if (!empty($requestPathParts[$requestPathIndex])) {
            $requestPathPart = $requestPathParts[$requestPathIndex];
            if (array_key_exists($requestPathPart, $routesIndex)) {
                $this->getRoutesFromIndex($routes,$routesIndex[$requestPathPart], $requestMethod, $requestPathParts, $requestPathIndex + 1);
            }
            if (array_key_exists(self::ROUTE_PARAMETER_WILDCARD, $routesIndex)) {
                $this->getRoutesFromIndex($routes,$routesIndex[self::ROUTE_PARAMETER_WILDCARD], $requestMethod, $requestPathParts, $requestPathIndex + 1);
            }
        }
        else if (array_key_exists(self::ROUTE_ACTIONS_KEY, $routesIndex)) {
            $testRoutes = &$routesIndex[self::ROUTE_ACTIONS_KEY];
            if (array_key_exists($requestMethod, $testRoutes)) {
                $this->getRoutesFromIndexActions($routes,$testRoutes[$requestMethod], $requestMethod,$requestPathParts);
            }
            if (array_key_exists(self::ROUTE_GENERIC_METHOD, $testRoutes)) {
                $this->getRoutesFromIndexActions($routes,$testRoutes[self::ROUTE_GENERIC_METHOD], $requestMethod, $requestPathParts);
            }
        }

        if (array_key_exists(self::ROUTE_GENERIC_ACTIONS_KEY, $routesIndex)) {
            $testRoutes = &$routesIndex[self::ROUTE_GENERIC_ACTIONS_KEY];
            if (array_key_exists($requestMethod, $testRoutes)) {
                $this->getRoutesFromIndexActions($routes,$testRoutes[$requestMethod], $requestMethod, $requestPathParts);
            }
            if (array_key_exists(self::ROUTE_GENERIC_METHOD, $testRoutes)) {
                $this->getRoutesFromIndexActions($routes,$testRoutes[self::ROUTE_GENERIC_METHOD], $requestMethod, $requestPathParts);
            }
        }
    }
1042091
public function post($requestUri, array $postData = [])
    {
        return $this->exec(
            [
                CURLOPT_URL => $requestUri,
                CURLOPT_POSTFIELDS => http_build_query($postData),
            ]
        );
    }
1273070
public function execute(RestRequestModel $apiRequest, $action, $indexedArgs)
    {
        $actionReader = $this->actionReader;
        $response = new ActionResponseModel();

        $actionCollection = $actionReader->getActionCollection();

        /* @var ActionModel $targetAction */
        if (!isset($actionCollection[$action][$apiRequest->getMethod()])) {
            throw new \Exception('Method '.$apiRequest->getMethod().' not supported by '.$action.' action.');
        }

        $targetAction = $actionCollection[$action][$apiRequest->getMethod()];

        if (!isset($targetAction)) {
            throw new \Exception('Unknown action "'.$action.'" for this controller.');
        }

        $query = [];
        parse_str($apiRequest->getQueryString(), $query);

        $content = $this->contentParser($apiRequest);

        // array of hashed based args
        $searchHashedArgs = [$query, $content];

        // get a hash of paramName => value ($preparedArgs), and a list of the params
        list($preparedArgs, $params) = $this->prepareArgs($targetAction, $indexedArgs, $searchHashedArgs);

        $callAction = [$actionReader->getController(), $targetAction->getClassMethod()];
        $callResponse = call_user_func_array($callAction, $preparedArgs);

        if ($callResponse) {
            $response
                ->setArgs($this->sanitizeArgs($preparedArgs))
                ->setParams($params)
                ->setResponse($callResponse)
                ->setPkgUuid($this->pkgUuid);
        }

        return $response;
    }
941373
private function validateRequestURI(&$requestURI)
    {
        if ($requestURI != '/' && substr($requestURI, -1) == '/') {
            $url = rtrim($requestURI, '/');

            if (php_sapi_name() === 'cli') {
                exit("Please ensure the URL you typed in does not have a trailing backslash.\n");
            }

            header("Location: " . $url);
            exit();
        }
    }
149661
protected static function defaultUpdateResponse(
        int $updated,
        string $index,
        UriInterface $requestUri,
        CrudInterface $crud,
        EncoderInterface $encoder
    ): ResponseInterface {
        $responses = static::defaultCreateResponses($requestUri, $encoder);
        if ($updated > 0 && ($model = $crud->read($index)) !== null) {
            assert(!($model instanceof PaginatedDataInterface));
            $response = $responses->getContentResponse($model);
        } else {
            $response = $responses->getCodeResponse(404);
        }

        return $response;
    }
1356371
private function requestResponseFor( $doi ) {

		$this->httpRequest->setOption( CURLOPT_FOLLOWLOCATION, true );

		$this->httpRequest->setOption( CURLOPT_RETURNTRANSFER, true );
		$this->httpRequest->setOption( CURLOPT_FAILONERROR, true );
		$this->httpRequest->setOption( CURLOPT_SSL_VERIFYPEER, false );

		$this->httpRequest->setOption( CURLOPT_URL, self::CROSSREF_CONTENT_API . $doi );

		$this->httpRequest->setOption( CURLOPT_HTTPHEADER, array(
			'Accept: application/vnd.citationstyles.csl+json',
			'Content-Type: application/x-www-form-urlencoded;charset=UTF-8'
		) );

		return $this->httpRequest->execute();
	}
1094871
public function post($uri, $content, $requestHeaders = array()) {
        try {
            return $this->executePost($uri, $content, $requestHeaders);
        } catch (Unauthenticated $e) {
            $this->auth_token->reset();
            return $this->executePost($uri, $content, $requestHeaders);
        }
    }