Get Full API Endpoint

@param  string $dynamicUrl
@return  string
328234
private function getFullApiUrl($dynamicUrl)
    {
        $staticUrl  = $this->configHelper->getApiUrl();
        return $staticUrl . self::API_CURRENT_VERSION . $dynamicUrl;
    }
1198202
protected function getEndpoint($method)
    {
        $endpoint = "calls";
        $searchParams = $this->getArgument("search_params");
        if (!is_null($searchParams)) {
            $queryString = http_build_query($searchParams);
            $this->delArgument("search_params");
            return "$endpoint?$queryString";
        }
        return $endpoint;
    }
953215
public function getCropEndpoint(
        $endpoint,
        $parameters = array(),
        $absolute = UrlGeneratorInterface::ABSOLUTE_PATH
    ) {
        $parameters = array_merge($parameters, array('endpoint' => $endpoint));

        return $this->router->generate($this->routeName, $parameters, $absolute);
    }
736654
protected static function getUrl($url)
    {
        Craft::debug('Fetching JSON from: '.$url, __METHOD__);

        $ch = curl_init();
        curl_setopt_array(
            $ch,
            [
                CURLOPT_URL => $url,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_MAXREDIRS => 5,
                CURLOPT_CONNECTTIMEOUT => 5,
            ]
        );
        $data = curl_exec($ch);

        $errorNumber = curl_errno($ch);
        $errorMessage = curl_error($ch);
        curl_close($ch);

        if ($errorNumber > 0) {
            Craft::warning('cURL got an error: '.$errorNumber.', '.$errorMessage, __METHOD__);
            return false;
        }

        return $data;
    }
1341198
public function getAbsoluteUrl(): string
    {
        if (!$this->absoluteUrl) {
            // Guessing we're a http endpoint.
            $this->absoluteUrl = 'http://'.
                ($this->getHeader('Host') ?? 'localhost').
                $this->getUrl();
        }

        return $this->absoluteUrl;
    }
281387
public function setApiEndpoint($url)
    {
        $this->apiEndpoint = $url;
        return $this->apiEndpoint === $url ? true : false;
    }
1337000
public function shorten($url)
    {
        // make the API call through the extended client
        $response = $this->fetchUrl($this->url(), $this->parameters($url));

        // read the shorted url from the response object
        $shorter_url = $this->parse($response);

        return $shorter_url;
    }
497746
public function getEndpoint($endpoint, $withHost = false, $forceReload = false)
    {
        $this->loadApiDefinition($forceReload);
        $url = "";
        if ($withHost) {
            $url = empty($this->options['host']) ? $this->definition->getHost() : $this->options['host'];
        }

        // If the base path is not already included, we need to add it.
        $url .= (empty($this->options['includeBasePath']) ? $this->definition->getBasePath() : '') . $endpoint;

        return $url;
    }
90542
public function getRequestedURI()
    {
        $endpoint = parse_url($this->apiEndpoint);

        // Replace Path of endpoint with requested path from curl
        $header = explode(' ', $this->curl->request_headers[0]);
        $endpoint['path'] = $header[1];

        return $endpoint['scheme'].'://'.$endpoint['host'].$endpoint['path'];
    }
710778
public function getFullUrl(
        $module = self::DEFAULT_MODULE,
        $controller = self::DEFAULT_CONTROLLER,
        array $params = []
    ): string {
        $scheme = Request::getUri()->getScheme() . '://';
        $host = Request::getUri()->getHost();
        $port = Request::getUri()->getPort();
        if ($port && !\in_array($port, [80, 443], true)) {
            $host .= ':' . $port;
        }
        $url = $this->getUrl($module, $controller, $params);
        return $scheme . $host . $url;
    }
1032766
protected function getServiceDescription($baseUrl)
    {
        return new Description(
            array(
                'baseUrl' => $baseUrl,
                'operations' => array(
                    'lookup' => array(
                        'uri' => 'postcodes/{postcode}',
                        'httpMethod' => 'GET',
                        'responseModel' => 'getResponse',
                        'parameters' => array(
                            'postcode' => array(
                                'location' => 'uri',
                                'description' => 'The postcode to look up.',
                                'required' => true
                            )
                        )
                    ),
                    'bulkLookup' => array(
                        'uri' => 'postcodes',
                        'httpMethod' => 'POST',
                        'responseModel' => 'getResponse',
                        'parameters' => array(
                            'postcodes' => array(
                                'location' => 'postField',
                                'description' => 'The postcodes to look up (max 100).',
                                'required' => true
                            )
                        )
                    ),
                    'reverseGeocode' => array(
                        'uri' => 'postcodes/lon/{longitude}/lat/{latitude}',
                        'httpMethod' => 'GET',
                        'responseModel' => 'getResponse',
                        'parameters' => array(
                            'longitude' => array(
                                'location' => 'uri',
                                'description' => 'The longitude to look up.',
                                'required' => true
                            ),
                            'latitude' => array(
                                'location' => 'uri',
                                'description' => 'The latitude to look up.',
                                'required' => true
                            ),
                            'limit' => array(
                                'location' => 'query',
                                'description' => 'Limit the number of postcodes returned (default 10, max 100).',
                                'required' => true
                            ),
                            'radius' => array(
                                'location' => 'query',
                                'description' => 'Limit the postcodes returned in metres (default 100, max 1000).',
                                'required' => true
                            )
                        )
                    ),
                    'bulkReverseGeocode' => array(
                        'uri' => 'postcodes',
                        'httpMethod' => 'POST',
                        'responseModel' => 'getResponse',
                        'parameters' => array(
                            'geolocations' => array(
                                'location' => 'postField',
                                'description' => 'The latitude and longitude coordinates to look up.',
                                'required' => true
                            )
                        )
                    ),
                    'matching' => array(
                        'uri' => 'postcodes',
                        'httpMethod' => 'GET',
                        'responseModel' => 'getResponse',
                        'parameters' => array(
                            'query' => array(
                                'location' => 'query',
                                'description' => 'The postcode query.'
                            ),
                            'limit' => array(
                                'location' => 'query',
                                'description' => 'Limit the number of postcodes returned (default 10, max 100).'
                            )
                        )
                    ),
                    'validate' => array(
                        'uri' => 'postcodes/{postcode}/validate',
                        'httpMethod' => 'GET',
                        'responseModel' => 'getResponse',
                        'parameters' => array(
                            'postcode' => array(
                                'location' => 'uri',
                                'description' => 'The postcode to validate.',
                                'required' => true
                            )
                        )
                    ),
                    'autocomplete' => array(
                        'uri' => 'postcodes/{postcode}/autocomplete',
                        'httpMethod' => 'GET',
                        'responseModel' => 'getResponse',
                        'parameters' => array(
                            'postcode' => array(
                                'location' => 'uri',
                                'description' => 'The partial postcode to autocomplete.',
                                'required' => true
                            ),
                            'limit' => array(
                                'location' => 'query',
                                'description' => 'Limit the number of postcodes returned (default 10, max 100).'
                            )
                        )
                    ),
                    'random' => array(
                        'uri' => 'random/postcodes',
                        'httpMethod' => 'GET',
                        'responseModel' => 'getResponse',
                    ),
                    'outwardCodeLookup' => array(
                        'uri' => 'outcodes/{outcode}',
                        'httpMethod' => 'GET',
                        'responseModel' => 'getResponse',
                        'parameters' => array(
                            'outcode' => array(
                                'location' => 'uri',
                                'description' => 'The outward code (first half of postcode) to get location data for.',
                                'required' => true
                            )
                        )
                    )
                ),
                'models' => array(
                    'getResponse' => array(
                        'type' => 'object',
                        'properties' => array(
                            'statusCode' => array(
                                'location' => 'statusCode'
                            )
                        ),
                        'additionalProperties' => array(
                            'location' => 'json'
                        )
                    )
                )
            )
        );
    }
347777
public static function getDomainFromURL($url)
	{
		$url = str_replace(self::getProtocolFromURL($url) . '://', '', $url);
		
		return explode('/', $url)[0];
	}
1134093
public function getFullUrl(): string
    {
        $queryString = $this->getQueryString();

        return sprintf(
            '%s%s%s',
            static::getBaseUri(),
            $this->getEndpoint(),
            ($queryString) ? '/?'.$queryString : ''
        );
    }
910086
protected function getRequestUrl()
    {
        $isTest = !array_key_exists('test', $this->getConfig()) || ((bool) $this->getConfig()['test']);

        return ($isTest ? $this->testEendpoint : $this->endpoint)."/{$this->getConfig()['id']}";
    }
81774
private function getUrl(string $url): string
    {
        $urlParts = parse_url($url);

        if ($urlParts === false) {
            throw new \ParseError("Could not parse URL: $url");
        }

        if ($this->baseUrl !== null && ! isset($urlParts['host'])) {
            $url = $this->baseUrl . '/' . ltrim($url, '/');
        }

        return $url;
    }
137186
public function getBusinessPageByUrl($url)
    {
        $BusinessTemplateInstance = null;

        //services
        $manager = $this->entityManager;
        $urlHelper = $this->urlHelper;
        $BusinessTemplateRepository = $manager->getRepository('VictoireBusinessPageBundle:BusinessTemplate');
        $BusinessTemplateHelper = $this->BusinessTemplateHelper;
        $businessEntityHelper = $this->businessEntityHelper;

        //
        $shorterUrl = $url;
        $shorterCount = 0;
        $BusinessTemplate = null;

        $watchDog = 1;

        //until we try to remove all parts
        while ($shorterUrl !== null && $BusinessTemplate === null) {
            //we remove the last part to look for a business entity page pattern
            $shorterUrl = $this->removeLastPart($shorterUrl);
            //the number of time the short has been done
            $shorterCount += 1;

            $searchUrl = $shorterUrl;

            //we add the % for the like query
            for ($i = 0; $i < $shorterCount; $i += 1) {
                $searchUrl .= '/%';
            }

            //we look for a business entity page pattern that looks like this url
            $BusinessTemplate = $BusinessTemplateRepository->findOneByLikeUrl($searchUrl);

            //does a business entity page pattern fit the url
            if ($BusinessTemplate !== null) {
                //we want the identifier
                $positionProperty = $BusinessTemplateHelper->getIdentifierPositionInUrl($BusinessTemplate);

                if ($positionProperty !== null) {
                    $position = $positionProperty['position'];
                    $businessProperty = $positionProperty['businessProperty'];

                    $entityIdentifier = $this->extractPartByPosition($url, $position);
                    //test the entity identifier
                    if ($entityIdentifier === null) {
                        throw new \Exception('The entity identifier could not be retrieved from the url.');
                    }

                    //name of the attribute used to get the entity
                    $attributeName = $businessProperty->getEntityProperty();

                    //get the entity
                    $entity = $businessEntityHelper->getEntityByPageAndBusinessIdentifier($BusinessTemplate, $entityIdentifier, $attributeName);

                    if ($entity === null) {
                        throw new \Exception('The entity with the identifier ['.$entityIdentifier.'] was not found');
                    }

                    //information found
                    $BusinessTemplateInstance = [
                        'BusinessTemplate' => $BusinessTemplate,
                        'entity'           => $entity,
                    ];
                } else {
                    throw new \Exception('The business entity page pattern ['.$BusinessTemplate->getId().'] has no identifier.');
                }
            }

            //the watchdog
            $watchDog += 1;

            if ($watchDog > 200) {
                throw new \Exception('The watchdog has been raised, there might be an infinite loop');
            }
        }

        return $BusinessTemplateInstance;
    }
1027074
public function getUrl($url)
    {
        if (is_array($url) && ! empty($url['route'])) {
            try {
                $Comet = \CometPHP\Comet::getInstance();
            } catch (\CometPHP\Exceptions\CometNotBooted $e) {
                return null;
            }

            $routeName = $url['route'];
            unset($url['route']);

            $generatedUrl = $Comet['routeGenerator']->generate(
                $routeName,
                $url
            );

            return $generatedUrl;
        }

        return $url;
    }