Imports the request data based on the schema if available

@param \PSX\Http\RequestInterface $request
@param \PSX\Api\Resource\MethodAbstract $method
@return \PSX\Record\RecordInterface
337765
protected function parseRequest(RequestInterface $request, MethodAbstract $method)
    {
        if ($method->hasRequest()) {
            $schema = $method->getRequest();
            if ($schema instanceof Passthru) {
                $data = $this->requestReader->getBody($request);
            } elseif ($schema instanceof SchemaInterface) {
                $data = $this->requestReader->getBodyAs($request, $method->getRequest(), $this->getValidator($method));
            } else {
                $data = new Record();
            }
        } else {
            $data = null;
        }

        return $data;
    }
535323
public function uploadAction(Request $request)
    {
        $form = $this->createForm(new FileImportType());
        $data = $form->handleRequest($request)->getData();
        $session = $this->getSession();

        try {
            $counters = $this->getSessionImporter()->handleUploadedFile($data['file']);
            if ($counters['new'] == 0 && $counters['updated'] == 0) {
                $session->getFlashBag()->set('warning', 'File import success, but not more modification found');
            } else {
                $session->getFlashBag()->set('info', "File import success, {$counters['new']} new and {$counters['updated']} update");
            }
        } catch (ImportException $e) {
            $session->getFlashBag()->set('error', 'Error while trying to import: '.$e->getMessage());
        }

        return $this->redirect($this->generateUrl('liip_translation_import'));
    }
662573
public function pagerfanta(Request $request)
    {
        $sql = $this->createQueryBuilder('data');
        $sql->select('data');
        $sql->andWhere('data.uploadFile = :uploadFile');
        $sql->setParameter('uploadFile', $request->get('import_id'));

        switch ($request->get('type', 'all')) {
            case 'success':
                $sql->andWhere('data.status = 1 or data.status = 2 or data.status = 0');
                break;
            case 'nochanges':
                $sql->andWhere('data.status = 0');
                break;
            case 'new':
                $sql->andWhere('data.status = 1');
                break;
            case 'update':
                $sql->andWhere('data.status = 2');
                break;
            case 'error':
                $sql->andWhere('data.status = 3');
                break;
        }

        return $sql->getQuery();
    }
422768
public function import() {
        $record = clone $this->framework;
        unset($record->children);

        $record->scaleid = $this->get_scale_id($record->scalevalues, $record->shortname);
        $record->scaleconfiguration = $this->get_scale_configuration($record->scaleid, $record->scaleconfiguration);
        unset($record->scalevalues);
        $record->contextid = context_system::instance()->id;

        $framework = api::create_framework($record);
        if ($this->useprogressbar === true) {
            $this->progress = new \core\progress\display_if_slow(get_string('importingfile', 'tool_lpimportcsv'));
        } else {
            $this->progress = new \core\progress\none();
        }

        $this->progress->start_progress('', (count($this->framework->children) * 2));
        raise_memory_limit(MEMORY_EXTRA);
        // Now all the children.
        foreach ($this->framework->children as $comp) {
            $this->progress->increment_progress();
            $this->create_competency($comp, null, $framework);
        }

        // Now create the rules.
        foreach ($this->framework->children as $record) {
            $this->progress->increment_progress();
            $this->set_rules($record);
            $this->set_related($record);
        }
        $this->progress->end_progress();

        $this->importer->cleanup();
        return $framework;
    }
250840
protected function save(RequestInterface $request)
    {
        $uri = $request->getUri();

        $this->setHost($uri->getHost());
        $this->setPort($uri->getPort());
        $this->setUrl((string) $uri);
        $this->setPath($uri->getPath());
        $this->setScheme($uri->getScheme());
        $this->setHeaders($request->getHeaders());
        $this->setProtocolVersion($request->getProtocolVersion());
        $this->setMethod($request->getMethod());

        // rewind to previous position after logging request
        $readPosition = null;
        if ($request->getBody() && $request->getBody()->isSeekable()) {
            $readPosition = $request->getBody()->tell();
        }

        $this->setBody($request->getBody() ? $request->getBody()->__toString() : null);

        if ($readPosition !== null) {
            $request->getBody()->seek($readPosition);
        }
    }
967160
public function createSymmetricEncryptedRequest(
        string $method,
        string $uri,
        string $body,
        SharedEncryptionKey $key,
        array $headers = []
    ): RequestInterface {
        return new Request(
            $method,
            $uri,
            $headers,
            Base64UrlSafe::encode(Simple::encrypt($body, $key))
        );
    }
293476
private function onBefore(RequestInterface $request)
    {
        $headers = $this->createHeaders($request);
        foreach ($headers as $headerKey => $headerValue) {
            $request = $request->withHeader($headerKey, $headerValue);
        }

        return $request;
    }
364042
public function onRequest( RequestInterface $request ) {
        $localizedUri = Uri::withQueryValue( $request->getUri(), 'lang', $this->getEndpoint()->getLang() );
        return $request->withUri($localizedUri);
    }
1079205
private function handleRequest(MethodInterface $method)
    {
        $result = $this->client->sendRequest(
            $method,
            $method->getMethod(),
            $method->getAction(),
            $this->getOptions($method)
        );

        if ($method instanceof MethodResultCollectionInterface) {
            return $this->mapper->mapCollection($result, $method);
        }

        return $this->mapper->map($result, $method->createResultObject());
    }
663536
public function execute(RequestInterface $request): RequestInterface
    {
        if (is_null($this->sessionToken)) {
            return $request;
        } else {
            return $request->withHeader(
                self::HEADER_CLIENT_AUTHENTICATION,
                [$this->sessionToken->getToken()]
            );
        }
    }
392172
public function create(string $method, string $uri, array $headers = [], $body = null): RequestInterface
    {
        if (!is_array($body)) {
            return $this->getRequestFactory()->createRequest($method, $uri, $headers, $body);
        }

        return $this->getRequestFactory()->createRequest($method, $uri, $headers);
    }
1088143
static function MethodData(RequestMethod $method, $name, $filter = FILTER_DEFAULT, $options = null)
    {
        switch ($method)
        {
            case RequestMethod::Get():
                return self::GetData($name, $filter, $options);
            
            case RequestMethod::Post():
                return self::PostData($name, $filter, $options);
            
            default:
                throw new \InvalidArgumentException('Request::MethodData is available for request methods POST and GET, only');
        }
    }
449510
public function methodNotAllowedResponse(RequestInterface $request)
    {
        if ($this->methodNotAllowedChain) {
            return $this->methodNotAllowedChain->execute(
                [$this->server, $request],
                $this->middlewares
            );
        }
        return Response::make('<html><head><title>405 Method Not Allowed</title></head><body bgcolor="white"><h1>405 Method Not Allowed</h1></body></html>', 405);
    }
238480
public function call(MethodInterface $method)
    {
        $this->validator->validate($method);

        return $this->handleRequest($method);
    }
1371067
public function request(RequestInterface $request)
    {
        $uri = $request->getUri()
            ->withPath('')
            ->withQuery('')
            ->withFragment('');

        $uri = $uri . $request->getRequestTarget();

        $request = $request->withRequestTarget($uri);

        return $this->doRequest($request);
    }
1147169
public function importStatusAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();

        $uploadFile = $em->getRepository('CompoImportBundle:UploadFile')->find($request->get('import_id'));

        $countImport = $this->getDoctrine()->getManager()->getRepository('CompoImportBundle:ImportLog')->count([
            'uploadFile' => $uploadFile->getId(),
        ]);

        return new JsonResponse([
            'status' => $uploadFile->getStatus(),
            'error' => $uploadFile->getMessage(),
            'count' => $countImport,
        ]);
    }
1303010
private static function requestApi($method, $body=null, $id=null) {
        $uri = Params::ENDPOINT . '/orders';
        if ($method == "get" || $method == "put")
            $uri .= "/$id";

        $request = new HttpRequest($method, $uri, self::$useSSL, self::$additionalCurlOpts);
        $request->setBasicAuthorization(self::$key);
        if (!is_null($body)) $request->setBodyAsJson($body);

        $response = $request->send();
        $response->checkCurlResponse();
        $jsonBody = $response->getBodyAsJson();
        if (!$response->isOk() || is_null($jsonBody) || !self::isBodyStatusOk($jsonBody)) {
            $httpStatus = $response->getHttpStatus();
            throw Exceptions\KondutoException::buildFromHttpStatus($jsonBody, $httpStatus);
        }

        return $response;
    }