Handle connect request

@param string $requestUri
@param string $requestMethod

@return $this

@throws \Exception
424909
public function handleRequest($requestUri = null, $requestMethod = null)
    {
        if (!$this->isConfigConsistent() && false) {
            throw new \LogicException('The client configuration is not consistent');
        }

        $pathInfo = $requestUri;

        if (false !== $pos = strpos($pathInfo, '?')) {
            $pathInfo = substr($pathInfo, 0, $pos);
        }

        $pathInfo = rawurldecode($pathInfo);

        $info = $this->getDispatcher()->dispatch($requestMethod, $pathInfo);

        if ($info[0] == Dispatcher::FOUND) {
            try {
                $response = $info[1]($this);

                if ($response instanceof ResponseInterface) {
                    $this->setResponse($response);
                }
            } catch (ResponseExceptionInterface $e) {
                $this->setResponse($e->getResponse());
            }
        } elseif (!$this->isAuthenticated()) {
            if (strtoupper($requestMethod) == 'GET') {
                $_SESSION[self::class][$this->getConfig()->getEntityID()]['targeted_path'] = $requestUri;
            }

            $request = $this->getSaml()->buildAuthnRequest();
            $_SESSION[self::class][$this->getConfig()->getEntityID()]['SAML_RelayState'] = $request->getRelayState();

            $this->setResponse($this->getSaml()->getHttpRedirectBindingResponse($request));
        }

        return $this;
    }
850370
public function onClientRequest(RequestEvent $event)
    {
        $errors = $this->validator->validate($event->getRequest());

        if (count($errors)) {
            throw new RequestException((string) $errors);
        }
    }
757702
public function connect()
	{
		$request  = $this->sendRequest($this->baseUrl."/auth", array('username' => $this->login, 'password' => $this->password), 2);

		$response = json_decode($request['body'], true);
		if (array_key_exists('error', $response))
		{
			throw new \Exception('Erreur '.$response['code'].' : '.$response['error']);
		} else {
			$this->token = $response['token'];
			$this->saveToken();
		}
	}
728198
public function handle($uri = null)
    {
        try {
            $returnedResponse = parent::handle($uri);
            return $this->handleWeb($returnedResponse);
        } catch (Throwable $e) {
            /** @noinspection PhpUnhandledExceptionInspection */
            return $this->handleException($e);
        }
    }
1144264
private function handleMatchingRoute(CalledUri $calledUri, Route $route): UriResource
    {
        if ($route->requiresAuth()) {
            return new ProtectedResource(
                $route->authConstraint(),
                $this->resolveResource($calledUri, $route),
                $this->injector
            );
        }

        return $this->resolveResource($calledUri, $route);
    }
459810
public function handle(RequestContract $request): ResponseContract
    {
        try {
            $this->app['events']->dispatch('request.handle', [$request]);

            $response = $this->sendRequest($request);
        } catch (Exception $e) {
            $this->reportException($e);
            $response = $this->toResponse($this->renderException($request, $e));
        } catch (Throwable $e) {
            $this->reportException($e = new FatalThrowableError($e));
            $response = $this->toResponse($this->renderException($request, $e));
        }

        $this->app['events']->dispatch('request.handled', [$request, $response]);

        return $response;
    }
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);
        }
    }
587067
public function sendHttpRequest(array $requestData, $method = 'POST')
    {
        // Perform re-login if required.
        if ('getchallenge' !== $requestData[ 'operation' ] && time() > $this->serviceExpireTime) {
            $this->login($this->userName, $this->accessKey);
        }

        $requestData[ 'sessionName' ] = $this->sessionName;
        
        try {
            switch ($method) {
                case 'GET':
                    $response = $this->httpClient->get($this->wsBaseURL, [ 'query' => $requestData, 'timeout' => $this->requestTimeout ]);
                    break;
                case 'POST':
                    $response = $this->httpClient->post($this->wsBaseURL, [ 'form_params' => $requestData, 'timeout' => $this->requestTimeout ]);
                    break;
                default:
                    throw new WSException("Unsupported request type {$method}");
            }
        } catch (RequestException $ex) {
            $urlFailed = $this->httpClient->getConfig('base_uri').$this->wsBaseURL;
            throw new WSException(
                sprintf('Failed to execute %s call on "%s" URL', $method, $urlFailed),
                'FAILED_SENDING_REQUEST',
                $ex
            );
        }

        $jsonRaw = $response->getBody();
        $jsonObj = json_decode($jsonRaw, true);

        $result = (is_array($jsonObj) && !self::checkForError($jsonObj))
            ? $jsonObj[ 'result' ]
            : null;
        return $result;
    }
224412
protected function buildUrl($requestUrl, $requestParams = [])
    {
        if (!empty($requestParams)) {
            $requestUrl = $requestUrl . '?' . http_build_query($requestParams);
        }

        return $requestUrl;
    }
758124
private function _setRequest()
	{
		if ($this->_requestUri !== NULL) {
            $this->_request = preg_replace('#(^/)|(^' . ROOT . ')|(/$)#', '', $this->_requestUri);

            if (! $this->_request) {
            	$this->_request = self::DEFAULT_MODULE . '/' . self::DEFAULT_VIEW;
            }

            $this->_requestVars = explode('/', $this->_request);
            if (count($this->_requestVars) == 1) {
				$this->_request       .= '/' . self::DEFAULT_VIEW;
				$this->_requestVars[]  = self::DEFAULT_VIEW;
            }

            return $this;
        }

        throw new Exception('Request URI is not available');
	}
1210283
public function allowsRequestMethod($requestMethod) {

		return empty($this->requestMethods) || in_array(strtoupper($requestMethod), $this->requestMethods);

	}
264962
protected function loadSystemUris($requestUri = null)
	{
		// Set the request URI.
		// @codeCoverageIgnoreStart
		if (!empty($requestUri))
		{
			$this->set('uri.request', $requestUri);
		}
		else
		{
			$this->set('uri.request', $this->detectRequestUri());
		}

		// @codeCoverageIgnoreEnd

		// Check to see if an explicit base URI has been set.
		$siteUri = trim($this->get('site_uri'));

		if ($siteUri != '')
		{
			$uri  = new Uri($siteUri);
			$path = $uri->toString(array('path'));
		}
		else
		{
			// No explicit base URI was set so we need to detect it. Start with the requested URI.
			$uri = new Uri($this->get('uri.request'));

			$requestUri = $this->input->server->getString('REQUEST_URI', '');

			// If we are working from a CGI SAPI with the 'cgi.fix_pathinfo' directive disabled we use PHP_SELF.
			if (strpos(PHP_SAPI, 'cgi') !== false && !ini_get('cgi.fix_pathinfo') && !empty($requestUri))
			{
				// We aren't expecting PATH_INFO within PHP_SELF so this should work.
				$path = \dirname($this->input->server->getString('PHP_SELF', ''));
			}
			else
			{
				// Pretty much everything else should be handled with SCRIPT_NAME.
				$path = \dirname($this->input->server->getString('SCRIPT_NAME', ''));
			}
		}

		// Get the host from the URI.
		$host = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));

		// Check if the path includes "index.php".
		if (strpos($path, 'index.php') !== false)
		{
			// Remove the index.php portion of the path.
			$path = substr_replace($path, '', strpos($path, 'index.php'), 9);
		}

		$path = rtrim($path, '/\\');

		// Set the base URI both as just a path and as the full URI.
		$this->set('uri.base.full', $host . $path . '/');
		$this->set('uri.base.host', $host);
		$this->set('uri.base.path', $path . '/');

		// Set the extended (non-base) part of the request URI as the route.
		if (stripos($this->get('uri.request'), $this->get('uri.base.full')) === 0)
		{
			$this->set('uri.route', substr_replace($this->get('uri.request'), '', 0, \strlen($this->get('uri.base.full'))));
		}

		// Get an explicitly set media URI is present.
		$mediaURI = trim($this->get('media_uri'));

		if ($mediaURI)
		{
			if (strpos($mediaURI, '://') !== false)
			{
				$this->set('uri.media.full', $mediaURI);
				$this->set('uri.media.path', $mediaURI);
			}
			else
			{
				// Normalise slashes.
				$mediaURI = trim($mediaURI, '/\\');
				$mediaURI = !empty($mediaURI) ? '/' . $mediaURI . '/' : '/';
				$this->set('uri.media.full', $this->get('uri.base.host') . $mediaURI);
				$this->set('uri.media.path', $mediaURI);
			}
		}
		else
		{
			// No explicit media URI was set, build it dynamically from the base uri.
			$this->set('uri.media.full', $this->get('uri.base.full') . 'media/');
			$this->set('uri.media.path', $this->get('uri.base.path') . 'media/');
		}
	}
913464
public static function createRequest(string $method, $uri): RequestInterface
    {
        if (\is_string($uri)) {
            $uri = Uri::createFromString($uri);
        }

        return new Request($method, $uri);
    }
480734
public function sendRequest(RequestEvent $event)
    {
        switch ($event->getMethod()) {
            case 'GET':
                $response = $this->getHttpClient()->getAdapter()->get($event->getRequest());
                break;
            case 'HEAD':
                $response = $this->getHttpClient()->getAdapter()->head($event->getRequest());
                break;
            case 'POST':
                $response = $this->getHttpClient()->getAdapter()->post($event->getRequest());
                break;
            case 'PUT':
                $response = $this->getHttpClient()->getAdapter()->put($event->getRequest());
                break;
            case 'PATCH':
                $response = $this->getHttpClient()->getAdapter()->patch($event->getRequest());
                break;
            case 'DELETE':
                $response = $this->getHttpClient()->getAdapter()->delete($event->getRequest());
                break;
            default:
                throw new RuntimeException(sprintf('Unknown request method "%s".', $event->getMethod()));
        }

        return $response;
    }
851637
private function updateRequestUri() : Request
    {
        $this->requestUri = $this->path;

        if ($this->queryString !== '') {
            $this->requestUri .= '?' . $this->queryString;
        }

        return $this;
    }
1093608
public function get(Provider $provider, $userId, $requestScope, $requestUri, array $requestHeaders = [])
    {
        return $this->send($provider, $userId, $requestScope, Request::get($requestUri, $requestHeaders));
    }
894906
public function setRequestUrl($requestUrl)
    {
        if (!$this->getUrlValidator()->isValid($requestUrl)) {
            throw new InvalidArgumentException('URL provided is invalid');
        }

        $this->requestUrl = $requestUrl;
    }