@param Request $request
@param array   $parameters

@throws \InvalidArgumentException

@return string
768804
protected function getCurrentUri(Request $request, array $parameters = [])
    {
        $params = $request->attributes->get('_route_params');

        return $this->generateUrl($request->attributes->get('_route'), array_merge($params, $parameters));
    }
1370687
public function handleRedirection($parameters, $request, $object = null)
    {
        if (is_array($parameters)) {
            if (array_key_exists('redirectTo', $parameters)) {
                if ($parameters['redirectTo'] === 'referer') {
                    return $this->redirect($this->getPreviousRoute($request));
                }
                if (isset($parameters['routingArgs'], $parameters['routingArgs']['id']) && $parameters['routingArgs']['id'] === 'object_id') {
                    $parameters['routingArgs']['id'] = $object->getId();
                }

                return $this->redirect(
                    $this->generateUrl(
                        $parameters['redirectTo'],
                        array_key_exists('routingArgs', $parameters) ? $parameters['routingArgs'] : []
                    )
                );
            }

            if (array_key_exists('return', $parameters) && $parameters['return'] === 'bool') {
                return true;
            }
        }

        if (method_exists($object, 'getParentEntity') && $object->getParentEntity()->getId()) {
            return $this->redirect(
                $this->generateUrl($this->tableViewName, ['id' => $object->getParentEntity()->getId()])
            );
        }

        return $this->redirect($this->generateUrl($this->tableViewName));
    }
1289588
private function parseParameters(array $parameters)
    {
        if (empty($parameters)) {
            return '';
        }

        $parameters = implode('&', array_map(
            function ($value, $key) {
                return sprintf('%s=%s', $key, urlencode($value));
            },
            $parameters,
            array_keys($parameters)
        ));

        return "&{$parameters}";
    }
464366
protected function convertRestRequest(array $request, array $httpParams = [])
    {
        $httpRequest = [];

        if (array_key_exists('query_parameters', $httpParams)) {
            $httpRequest['query_parameters'] = $httpParams['query_parameters'];
            unset($httpParams['query_parameters']);
        }

        if (!array_key_exists('route', $request)) {
            if (!array_key_exists($request['controller'], $this->routesDescription)) {
                throw new InvalidArgumentException('Unable to retrieve http route: controller "' . $request['controller'] . '" information not found');
            }

            if (!array_key_exists($request['action'], $this->routesDescription[$request['controller']])) {
                throw new InvalidArgumentException('Unable to retrieve http route: action "' . $request['controller'] . ':' . $request['action'] . '" information not found');
            }

            $httpRequest['route'] = $this->routesDescription[$request['controller']][$request['action']]['route'];

            if ($request['controller'] == 'document' && $request['action'] == 'create' && !array_key_exists('_id', $request)) {
                $httpRequest['route'] = str_replace(':_id/', '', $httpRequest['route']);
            }
        } else {
            $httpRequest['route'] = $request['route'];
            unset($request['route']);
        }

        // replace http route parameters
        if (array_key_exists('collection', $request)) {
            $httpParams[':collection'] = $request['collection'];
        }

        if (array_key_exists('index', $request)) {
            $httpParams[':index'] = $request['index'];
        }

        if (array_key_exists('_id', $request)) {
            $httpParams[':_id'] = $request['_id'];
        }

        foreach ($httpParams as $pattern => $value) {
            $httpRequest['route'] = str_replace($pattern, $value, $httpRequest['route']);
        }

        if (!array_key_exists('method', $request)) {
            if (!array_key_exists($request['controller'], $this->routesDescription)) {
                throw new InvalidArgumentException('Unable to retrieve http method: controller "' . $request['controller'] . '" information not found');
            }

            if (!array_key_exists($request['action'], $this->routesDescription[$request['controller']])) {
                throw new InvalidArgumentException('Unable to retrieve http method: action "' . $request['controller'] . ':' . $request['action'] . '" information not found');
            }

            $httpRequest['method'] = mb_strtoupper($this->routesDescription[$request['controller']][$request['action']]['method']);
        } else {
            $httpRequest['method'] = mb_strtoupper($request['method']);
            unset($request['method']);
        }

        $httpRequest['request'] = $request;

        return $httpRequest;
    }
37464
protected function mapRequestParameters($parameters)
    {
        if (empty($parameters) || !array_key_exists('query', $parameters)) {
            return '';
        }

        $exclude = [
            'q',
            'count',
            'min_id',
            'max_id',
            'min_tag_id',
            'max_tag_id',
            'lat',
            'lng',
            'distance',
            'text',
            'max_like_id',
            'action',
            'cursor',
            'access_token',
        ];

        $modifiers = array_except($parameters['query'], $exclude);
        $return    = implode('_', array_keys($modifiers));
        return rtrim("_$return", '_');
    }
1020300
public function resolve(Request $request)
    {
        $attributes = $this->urlMatcher->match($request->getPathInfo());
        $controllerNotation = explode('@', $attributes['_route']);
        unset($attributes['_route']);

        $controller = explode(':', $controllerNotation[0]);

        $total = count($controller);
        $last = $total - 1;

        $controller[$total] = sprintf('%sController', $controller[$last]);
        $controller[$last] = 'Controller';

        $action = sprintf('%sAction', $controllerNotation[1]);
        unset($controllerNotation);

        $class = implode('\\', $controller);
        if (!class_exists($class)) {
            throw new \InvalidArgumentException(sprintf('Class "%s" is not exist.', $class));
        }

        $implements = class_implements($class);
        if (!array_key_exists(ControllerInterface::class, $implements)) {
            throw new \InvalidArgumentException(sprintf('"%s" must implement "%s"', $class, ControllerInterface::class));
        }

        return array(
            '_controller' => $class,
            '_action' => $action,
            '_parameters' => $attributes,
        );
    }
924141
protected function fetchToken(Request $request): string
    {
        if ($request->hasHeader(self::HEADER)) {
            return (string)$request->getHeaderLine(self::HEADER);
        }

        $data = $request->getParsedBody();
        if (is_array($data) && isset($data[self::PARAMETER])) {
            if (is_string($data[self::PARAMETER])) {
                return (string)$data[self::PARAMETER];
            }
        }

        return '';
    }
337527
protected function request($url, $parameters = array(), $request = false)
        {
            $this->lastRequest = $url;
            $this->lastRequestData = $parameters;
            $this->responseHeaders = array();

            $curl = curl_init($url);

            $curlOptions = array(
                CURLOPT_SSL_VERIFYPEER => false,
                CURLOPT_REFERER        => $url,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_HEADERFUNCTION => array($this, 'parseHeader'),
            );

            if (! empty($parameters) || ! empty($request)) {
                if (! empty($request)) {
                    $curlOptions[ CURLOPT_CUSTOMREQUEST ] = $request;
                    $parameters = http_build_query($parameters);
                } else {
                    $curlOptions[ CURLOPT_POST ] = true;
                }

                $curlOptions[ CURLOPT_POSTFIELDS ] = $parameters;
            }

            curl_setopt_array($curl, $curlOptions);

            $response = curl_exec($curl);
            $error    = curl_error($curl);

            $this->lastRequestInfo = curl_getinfo($curl);

            curl_close($curl);

            if (! empty($error)) {
                throw new \Exception($error);
            }

            return $this->parseResponse($response);
        }
1309157
public function parseQueryFromRequest(RequestInterface $request = null)
    {
        if ($request === null && $this->currentRequest === null) {
            throw new \InvalidArgumentException('No request is provided.');
        }

        $req = $request === null
            ? $this->currentRequest
            : $request;

        /* Rempli un array des paramètres de l'Uri. */
        parse_str($req->getUri()->getQuery(), $parseQuery);

        /*
         * Pour avoir le paramètre non identifié par une clé.
         * Exemple : http://exemple.com/?first_param = 'first_param'
         * Il faut prendre le 1er élément du tableau inversé des paraètres de l'Uri.
         */
        return !empty($parseQuery)
            ? rawurlencode(array_keys($parseQuery)[ 0 ])
            : '%2F';
    }
50874
public function createRequest($method, $url = '', array $headers = [])
    {
        if (!is_string($url)) {
            throw new InvalidArgumentException('Url parameter must be a valid string!!');
        }

        $url = new Url((isset($this->baseUrl)?$this->baseUrl->toString():'').$url);

        $request = $this->requestFactory->build($method, $url, $headers);
        $request->setClient($this);

        return $request;
    }
97474
public function apply(Request $request, ParamConverter $configuration)
    {
        $slug = $request->get('slug', null);
        $username = $request->get('username', null);
        $id = $request->get('id', null);

        if ($slug)
        {
            $searchArray = array('slug' => $slug);
        }
        elseif($username)
        {
            $searchArray = array('username' => $username);
        }
        elseif($id)
        {
            $searchArray = array('id' => $id);
        }
        else
        {
            throw new \InvalidArgumentException('Route attribute is missing');
        }

        $class = $this->targetEntitiesArray[$configuration->getClass()];

        $repository = $this->doctrine->getRepository($class);

        $object = $repository->findOneBy( $searchArray );

        if(!$object)
            throw new NotFoundHttpException("Sorry, requested resource can't be found.");

        $request->attributes->set($configuration->getName(), $object);

    }
315391
public function saveAction(Request $request)
    {
        $objectType = $request->get('objectType');
        $objectId = $request->get('objectId');
        $data = $request->get('identities');

        if (!$data) {
            throw new InvalidArgumentException('No save data.');
        }

        $identities = json_decode($data, true);

        $objectIdentityResolver = $this->get('phlexible_access_control.object_identity_resolver');
        $objectIdentity = $objectIdentityResolver->resolve($objectType, $objectId);

        $accessManager = $this->get('phlexible_access_control.access_manager');
        $acl = $accessManager->findAcl($objectIdentity);

        if (!$acl) {
            $acl = $accessManager->createAcl($objectIdentity);
        }

        foreach ($acl->getEntries() as $ace) {
            $acl->removeEntry($ace);
        }
        foreach ($identities as $objectIdentity) {
            if ($objectIdentity['mask'] === null && $objectIdentity['stopMask'] === null && $objectIdentity['noInheritMask'] === null) {
                continue;
            }

            $ace = new Entry(
                $acl,
                $objectIdentity['objectType'],
                $objectIdentity['objectId'],
                $objectIdentity['securityType'],
                $objectIdentity['securityId'],
                $objectIdentity['mask'],
                $objectIdentity['stopMask'],
                $objectIdentity['noInheritMask']
            );

            $acl->addEntry($ace);
        }

        $accessManager->updateAcl($acl);

        return new ResultResponse(true, 'Rights saved.');
    }
581479
public function getParam($key)
    {
        if (!isset($this->params[$key])) {
            throw new InvalidArgumentException("The request parameter with key '$key' is invalid."); 
        }
        return $this->params[$key];
    }
102567
public function getObject(array $parameters = array())
    {
        if ($this->url === null) {
            throw new \InvalidArgumentException('Missing URL.');
        }

        if ($this->endpoint === null) {
            $this->endpoint = $this->discover($this->url);
        }

        $sign = '?';
        if ($query = parse_url($this->endpoint, PHP_URL_QUERY)) {
            $sign = '&';

            parse_str($query, $parameters);
        }

        if (!isset($parameters['url'])) {
            $parameters['url'] = $this->url;
        }
        if (!isset($parameters['format'])) {
            $parameters['format'] = 'json';
        }

        $client = new Client(
            sprintf('%s%s%s', $this->endpoint, $sign, http_build_query($parameters))
        );

        $data = $client->send();

        switch ($parameters['format']) {
            case 'json':
                $data = json_decode($data);
                if (!is_object($data)) {
                    throw new \InvalidArgumentException('Could not parse JSON response.');
                }

                break;

            case 'xml':
                libxml_use_internal_errors(true);
                $data = simplexml_load_string($data);
                if (!$data instanceof \SimpleXMLElement) {
                    $errors = libxml_get_errors();
                    $error  = array_shift($errors);
                    libxml_clear_errors();
                    libxml_use_internal_errors(false);
                    throw new \InvalidArgumentException($error->message, $error->code);
                }

                break;
        }

        return Object::factory($data);
    }
82705
public function guessTemplateName($controller, Request $request)
    {
        if (\is_object($controller) && method_exists($controller, '__invoke')) {
            $controller = [$controller, '__invoke'];
        } elseif (!\is_array($controller)) {
            throw new \InvalidArgumentException(sprintf('First argument of %s must be an array callable or an object defining the magic method __invoke. "%s" given.', __METHOD__, \gettype($controller)));
        }

        $className = $this->getRealClass(\get_class($controller[0]));

        $matchController = null;
        foreach ($this->controllerPatterns as $pattern) {
            if (preg_match($pattern, $className, $tempMatch)) {
                $matchController = str_replace('\\', '/', strtolower(preg_replace('/([a-z\d])([A-Z])/', '\\1_\\2', $tempMatch[1])));
                break;
            }
        }
        if (null === $matchController) {
            throw new \InvalidArgumentException(sprintf('The "%s" class does not look like a controller class (its FQN must match one of the following regexps: "%s")', \get_class($controller[0]), implode('", "', $this->controllerPatterns)));
        }

        if ('__invoke' === $controller[1]) {
            $matchAction = $matchController;
            $matchController = null;
        } else {
            $matchAction = preg_replace('/Action$/', '', $controller[1]);
        }

        $matchAction = strtolower(preg_replace('/([a-z\d])([A-Z])/', '\\1_\\2', $matchAction));
        $bundleName = $this->getBundleForClass($className);

        return sprintf(($bundleName ? '@'.$bundleName.'/' : '').$matchController.($matchController ? '/' : '').$matchAction.'.'.$request->getRequestFormat().'.twig');
    }
86241
public static function dataTableSorting($request, $parameters, $indexColumns)
    {
        $order      = $request->input('order');
        $columns    = $request->input('columns');

        if(is_array($order[0]) && isset($order[0]['column']) && isset($order[0]['dir']) && $columns[(int)$order[0]['column']]['orderable'] == 'true')
        {
            $parameters['order']['column']  = is_array($indexColumns[$order[0]['column']])? $indexColumns[$order[0]['column']]['data'] : $indexColumns[$order[0]['column']];
            $parameters['order']['dir']     = $order[0]['dir'];
        }

        return $parameters;
    }
46153
public function sendRequest($request)
	{
		// Check if request was passed in
		if (!$request) {
			throw new InvalidArgumentException('No data was passed into the provision request');
		}

		return $this->client->post($this->prv_url, [
			'Content-type'             => 'text/xml',
			'Content-length'           => strlen($request),
			'MMProvision-Access-Token' => $this->prv_token,
		], $request);
	}