ScriptFUSION\Porter\Net\Http\HttpConnector::fetchFreshData PHP Method

fetchFreshData() public method

public fetchFreshData ( string $source, EncapsulatedOptions $options = null ) : string
$source string Source.
$options ScriptFUSION\Porter\Options\EncapsulatedOptions Optional. Options.
return string Response.
    public function fetchFreshData($source, EncapsulatedOptions $options = null)
    {
        if ($options && !$options instanceof HttpOptions) {
            throw new \InvalidArgumentException('Options must be an instance of HttpOptions.');
        }
        return \ScriptFUSION\Retry\retry($this->getTries(), function () use($source, $options) {
            if (false === ($response = @file_get_contents($this->getOrCreateUrlBuilder()->buildUrl($source, $options ? $options->getQueryParameters() : [], $this->getBaseUrl()), false, stream_context_create(['http' => ['ignore_errors' => true] + array_merge($this->options->extractHttpContextOptions(), $options ? $options->extractHttpContextOptions() : [])])))) {
                $error = error_get_last();
                throw new HttpConnectionException($error['message'], $error['type']);
            }
            $code = explode(' ', $http_response_header[0], 3)[1];
            if ($code < 200 || $code >= 400) {
                throw new HttpServerException("HTTP server responded with error: \"{$http_response_header['0']}\".\n\n{$response}");
            }
            return $response;
        }, new ExponentialBackoffErrorHandler());
    }