Parse request

@param \Zend\Http\Request $request
@param \Zend\Http\Response $request
@return string|null $error
329567
public function parse( Request $request, Response $response )
    {
        $error = parent::parse( $request, $response );

        if ( $error )
        {
            return $error;
        }

        $method = null;
        $params = xmlrpc_decode_request(
            $request->getContent(),
            $method,
            'utf-8'
        );

        if ( ! $params )
        {
            return self::PARSE;
        }

        if ( empty( $method ) || empty( $params ) )
        {
            return self::INVALID_REQUEST;
        }

        $this->method   = $method;
        $this->params   = $params;

        return null;
    }
503151
public function detect(Request $request, Response $response = null)
	{
		$localeId = null;

		/* @var $detector Detector\DetectorInterface */
		foreach ($this->detectors as $detector) {
			
			$localeId = $detector->detect($request);
			
			if ( ! empty($localeId)) {
				
				if ($this->hasLocale($localeId) && ($this->processInactive || $this->isActive($localeId))) {
					$this->setCurrent($localeId);
					break;
				}
			}
		}

		if (empty($localeId)) {
			throw new Exception\RuntimeException("Could not detect locale for request '{$request->getBaseUrl()}'");
		}

		/* @var $storage Storage\StorageInterface */

		// @FIXME: there is no response object here.
		foreach ($this->storages as $storage) {
			$storage->store($request, $response, $localeId);
		}
	}
319252
public function parseRequest($request)
    {
        if (count($this->availableLanguages) > 0) {
            if (preg_match('/\/(' . implode('|', $this->availableLanguages) . ')(.*)/si', $request->url, $matches)) {
                Yii::$app->language = $matches[1];
            }
        }

        $res = parent::parseRequest($request);
        if (is_array($res)) {
            if (isset($res[1]['language']) && in_array($res[1]['language'], $this->availableLanguages)) {
                Yii::$app->language = $res[1]['language'];
            }
        }
        return $res;
    }
499543
public function register(Request $request): Response
    {
        $contentTypeIdentifier = $this->getConfigResolver()->getParameter('user.content_type_identifier', 'ngsite');
        $contentType = $this->getRepository()->getContentTypeService()->loadContentTypeByIdentifier($contentTypeIdentifier);
        $languages = $this->getConfigResolver()->getParameter('languages');
        $userCreateStruct = $this->userService->newUserCreateStruct(
            null,
            null,
            null,
            $languages[0],
            $contentType
        );

        $userCreateStruct->enabled = (bool) $this->getConfigResolver()->getParameter('user.auto_enable', 'ngsite');
        $userCreateStruct->alwaysAvailable = (bool) $contentType->defaultAlwaysAvailable;

        $data = new DataWrapper($userCreateStruct, $userCreateStruct->contentType);

        $formBuilder = $this->formFactory->createBuilder(
            CreateUserType::class,
            $data,
            [
                'translation_domain' => 'ngsite_user',
            ]
        );

        $form = $formBuilder->getForm();
        $form->handleRequest($request);

        if (!$form->isValid()) {
            return $this->render(
                $this->getConfigResolver()->getParameter('template.user.register', 'ngsite'),
                [
                    'form' => $form->createView(),
                ]
            );
        }

        $users = $this->userService->loadUsersByEmail($form->getData()->payload->email);

        if (!empty($users)) {
            return $this->render(
                $this->getConfigResolver()->getParameter('template.user.register', 'ngsite'),
                [
                    'form' => $form->createView(),
                    'error' => 'email_in_use',
                ]
            );
        }

        try {
            $this->userService->loadUserByLogin($form->getData()->payload->login);

            return $this->render(
                $this->getConfigResolver()->getParameter('template.user.register', 'ngsite'),
                [
                    'form' => $form->createView(),
                    'error' => 'username_taken',
                ]
            );
        } catch (NotFoundException $e) {
            // do nothing
        }

        $userGroupId = $this->getConfigResolver()->getParameter('user.user_group_content_id', 'ngsite');

        $preUserRegisterEvent = new UserEvents\PreRegisterEvent($data->payload);
        $this->eventDispatcher->dispatch(SiteEvents::USER_PRE_REGISTER, $preUserRegisterEvent);
        $data->payload = $preUserRegisterEvent->getUserCreateStruct();

        /** @var \eZ\Publish\API\Repository\Values\User\User $newUser */
        $newUser = $this->getRepository()->sudo(
            static function (Repository $repository) use ($data, $userGroupId): User {
                $userGroup = $repository->getUserService()->loadUserGroup($userGroupId);

                return $repository->getUserService()->createUser(
                    $data->payload,
                    [$userGroup]
                );
            }
        );

        $userRegisterEvent = new UserEvents\PostRegisterEvent($newUser);
        $this->eventDispatcher->dispatch(SiteEvents::USER_POST_REGISTER, $userRegisterEvent);

        if ($newUser->enabled) {
            return $this->render(
                $this->getConfigResolver()->getParameter('template.user.register_success', 'ngsite')
            );
        }

        if ($this->getConfigResolver()->getParameter('user.require_admin_activation', 'ngsite')) {
            return $this->render(
                $this->getConfigResolver()->getParameter('template.user.activate_admin_activation_pending', 'ngsite')
            );
        }

        return $this->render(
            $this->getConfigResolver()->getParameter('template.user.activate_sent', 'ngsite')
        );
    }
1344116
public function handle(Request $request)
    {
        foreach ($this->staticContentPatterns as $ptn) {
            if (preg_match($ptn, $request->getRequestUri(), $m)) {
                $path = urldecode(parse_url($m[1], PHP_URL_PATH));
                if (!is_file($this->webDir . $path)) {
                    return $this->createDefaultNotFoundResponse($path);
                }
            }
        }
        return null;
    }
237689
public function parse()
    {
        if (array_key_exists('PHP_AUTH_USER', $_SERVER)) { // mod_php
            $this->name = $_SERVER['PHP_AUTH_USER'];
            $this->password = array_key_exists('PHP_AUTH_PW', $_SERVER) ? $_SERVER['PHP_AUTH_PW'] : null;
        } elseif (array_key_exists('HTTP_AUTHENTICATION', $_SERVER)) { // most other servers
            if (strpos(strtolower($_SERVER['HTTP_AUTHENTICATION']), 'basic') === 0) {
                $userdata = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHENTICATION'], 6)));
                list($this->name, $this->password) = $userdata;
            }
        } elseif (array_key_exists('REDIRECT_HTTP_AUTHORIZATION', $_SERVER)) { // most other servers
            if (strpos(strtolower($_SERVER['REDIRECT_HTTP_AUTHORIZATION']), 'basic') === 0) {
                $userdata = explode(':', base64_decode(substr($_SERVER['REDIRECT_HTTP_AUTHORIZATION'], 6)));
                list($this->name, $this->password) = $userdata;
            }
        }
    }
1207361
public function findAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();

        $productRepo = $em->getRepository(Product::class);
        $productsQb = $productRepo->findAllFilteredQB([
            'q' => $request->get('q')
        ]);
        $products = $productsQb->getQuery()->getResult();
        $productArr = [];
        /* @var Product $product */
        foreach ($products as $product) {
            $productArrItem = [
                'id' => $product->getId(),
                'text' => $product->getName() . ' - $' . $product->getPrice()
            ];

            array_push($productArr, $productArrItem);
        }

        return new JsonResponse($productArr);

    }
403480
protected function call($request)
    {
        if(!isset($request['query']))
        {
            $request['query'] = [];
        }

        $method  = 'GET';
        $headers = $this->getHeaders();
        $query   = http_build_query($request['query']);
        $url     = "{$this->domain}/{$request['route']}?$query";

        try {
            $request = $this->getClient()->request($method, $url, [
                'headers' => $headers
            ]);

            $response = $request->getBody()->getContents();

            return json_decode($response, true);

        } catch (RequestException $e) {
            $response = $e->getResponse();
            $response = json_decode($response, true);
            return $response;
        } catch (\Exception $e) {
            return ['error' => $e->getCode(), 'error_description' => $e->getMessage()];
        }
    }
190620
public function parse()
    {
        if ($this->body === false) {
            return null;
        }

        $result = [];
        $key = null;
        foreach ($this->body as $value) {
            if (!is_null($key)) {
                $result[$key] = $value;
                $key = null;
            } else {
                $key = $value;
            }
        }

        return $result;
    }
56906
protected function parseOperation($request = [], $params = [])
    {
        $meta = $params + compact('request');
        $method = $request['method'];
        //        $header = $request['header'];
        $body = $request['body'];
        $url = $request['url'];
        $data = [
            'httpMethod' => $method,
            'uri' => $this->parseUri($url, $meta),
            'responseModel' => 'getResponse',
            'parameters' => $this->parseParams($url, $body['raw'], $meta),
        ];
        return $data;

    }
604234
public function handleHttpRequest($request)
    {
        $this->parseRequestBase($request);

        $data = $this->parseRule();
        $path = $data[0] ?? $this->routeParams->path;
        if ($path) {
            $this->parsePath($path);
        }
        if (!empty($data[1])) {
            foreach ($data[1] as $name => $value) {
                $request->get[$name] = $value;
            }
        }
    }
1339457
public function showSearchResultsAction(Request $request)
    {
        $response = new Response();
        $searchText = '';
        $searchCount = 0;

        // Creating a form using Symfony's form component
        $simpleSearch = new SimpleSearch();
        $form = $this->createForm($this->get('ezdemo.form.type.simple_search'), $simpleSearch);
        $form->handleRequest($request);

        $pager = null;

        if ($form->isValid()) {
            /** @var SearchHelper $searchHelper */
            $searchHelper = $this->get('ezdemo.search_helper');

            if (!empty($simpleSearch->searchText)) {
                $searchText = $simpleSearch->searchText;

                $pager = $searchHelper->searchForPaginatedContent(
                    $searchText,
                    $request->get('page', 1),
                    $this->getConfigResolver()->getParameter('languages')
                );

                $searchCount = $pager->getNbResults();
            }
        }

        return $this->render(
            'eZDemoBundle:search:search.html.twig',
            array(
                'searchText' => $searchText,
                'searchCount' => $searchCount,
                'pagerSearch' => $pager,
                'form' => $form->createView(),
            ),
            $response
        );
    }
972707
public function doRequestInProcess($request)
    {
        if ($this->mockedResponse) {
            $response = $this->mockedResponse;
            $this->mockedResponse = null;
            return $response;
        }

        $requestCookie = $request->getCookies();
        $requestServer = $request->getServer();
        $requestFiles = $this->remapFiles($request->getFiles());

        $parseResult = parse_url($request->getUri());
        $uri = $parseResult["path"];
        if (array_key_exists("query", $parseResult)) {
            $uri .= "?" . $parseResult["query"];
        }

        $requestRequestArray = $this->remapRequestParameters($request->getParameters());

        $requestServer['REQUEST_METHOD'] = strtoupper($request->getMethod());
        $requestServer['REQUEST_URI'] = $uri;
        $requestServer['HTTP_HOST'] = $this->domain;
        $requestServer['SERVER_PROTOCOL'] = 'HTTP/1.1';
        $requestServer['SERVER_NAME'] = $this->domain;
        $requestServer['HTTP_CLIENT_IP'] = '127.0.0.1';

        $this->index = $this->uriToIndexMapper->getIndexForUri($uri);

        $phpSelf = str_replace($this->rootFolder, '', $this->index);
        $requestServer['PHP_SELF'] = $phpSelf;

        $env = [
            'headers' => $this->headers,
            'cookie' => $requestCookie,
            'server' => $requestServer,
            'files' => $requestFiles,
            'request' => $requestRequestArray,
        ];

        if (strtoupper($request->getMethod()) == 'GET') {
            $env['get'] = $env['request'];
        } else {
            $env['post'] = $env['request'];
        }

        $requestScript = dirname(dirname(__DIR__)) . '/scripts/request.php';

        $command = PHP_BINARY .
            ' ' . escapeshellarg($requestScript) .
            ' ' . escapeshellarg($this->index) .
            ' ' . escapeshellarg(base64_encode(serialize($env)));

        $process = new Process($command);
        $process->run();
        $rawProcessOutput = $process->getOutput();

        $unserializedResponse = @unserialize(base64_decode($rawProcessOutput));

        if (false === $unserializedResponse) {
            $message = 'Server responded with: ' . $rawProcessOutput;
            throw new ModuleException(\Codeception\Module\WordPress::class, $message);
        }

        $_SERVER = empty($unserializedResponse['server']) ? [] : $unserializedResponse['server'];
        $_FILES = empty($unserializedResponse['files']) ? [] : $unserializedResponse['files'];
        $_REQUEST = empty($unserializedResponse['request']) ? [] : $unserializedResponse['request'];
        $_GET = empty($unserializedResponse['get']) ? [] : $unserializedResponse['get'];
        $_POST = empty($unserializedResponse['post']) ? [] : $unserializedResponse['post'];

        $content = $unserializedResponse['content'];
        $headers = $this->replaceSiteUrlDeep($unserializedResponse['headers'], $this->url);

        $response = new Response($content, $unserializedResponse['status'], $headers);

        return $response;
    }
1222044
public function match(Request $request)
	{
		foreach ($this->routes->filterByMethod($request->getMethod()) as $route)
		{
			if ($route->isMatch($request->getPathInfo()))
			{
				return $route;
			}
		}

		return null;
	}
477863
public function parse(Request $request)
    {
        if (!$request->has($this->name)) {
            return;
        }

        $this->applied = true;

        $this->extractTokens($request->input($this->name));

        $this->value = [
            Carbon::parse($this->from)->setTimezone('UTC'),
            Carbon::parse($this->to)->setTimezone('UTC')
        ];
    }
478546
public function parseRequest(Request $request)
    {
        try {
            $this->setPath($request->get('_route'));

            $this->setQuery($request->query->all());

            $this->setRouteParams($request->attributes->get('_route_params'));

            if ($request->get('page')) {
                $this->setCurrentPage((int)$request->get('page'));
            }

            if ($request->get('maxItems')) {
                $this->setNumberOfElementsPerPage((int)$request->get('maxItems'));
            }

        } catch (\Exception $e) {
            throw new \Exception ('The request provided is not a valid Request Object');
        }

        return $this;
    }
902752
public function route(Request $request)
    {
        foreach ($this->routes as $route) {
            if ($route->matches($request)) {
                return $route;
            }
        }

        return null;
    }