public function update(string $remoteFile = IniLoaderInterface::PHP_INI) : void
    {
        $this->logger->debug('started fetching remote file');

        try {
            $cachedVersion = $this->checkUpdate();
        } catch (NoNewVersionException $e) {
            return;
        } catch (NoCachedVersionException $e) {
            $cachedVersion = 0;
        }

        $loader = new IniLoader();
        $loader->setRemoteFilename($remoteFile);

        $uri = $loader->getRemoteIniUrl();

        try {
            /** @var \Psr\Http\Message\ResponseInterface $response */
            $response = $this->client->request('get', $uri, ['connect_timeout' => $this->connectTimeout]);
        } catch (\GuzzleHttp\Exception\GuzzleException $e) {
            throw new FetcherException(
                sprintf(
                    'an error occured while fetching remote data from URI %s',
                    $uri
                ),
                0,
                $e
            );
        }

        if (200 !== $response->getStatusCode()) {
            throw new FetcherException(
                sprintf(
                    'an error occured while fetching remote data from URI %s: StatusCode was %d',
                    $uri,
                    $response->getStatusCode()
                )
            );
        }

        try {
            $content = $response->getBody()->getContents();
        } catch (\Exception $e) {
            throw new FetcherException('an error occured while fetching remote data', 0, $e);
        }

        if (empty($content)) {
            $error = error_get_last();

            throw FetcherException::httpError($uri, $error['message'] ?? '');
        }

        $this->logger->debug('finished fetching remote file');
        $this->logger->debug('started updating cache from remote file');

        $converter = new Converter($this->logger, $this->cache);
        $this->storeContent($converter, $content, $cachedVersion);

        $this->logger->debug('finished updating cache from remote file');
    }
public function update(string $remoteFile = IniLoaderInterface::PHP_INI) : void
    {
        $this->logger->debug('started fetching remote file');

        try {
            $cachedVersion = $this->checkUpdate();
        } catch (NoNewVersionException $e) {
            return;
        } catch (NoCachedVersionException $e) {
            $cachedVersion = 0;
        }

        $loader = new IniLoader();
        $loader->setRemoteFilename($remoteFile);

        $uri = $loader->getRemoteIniUrl();

        try {
            /** @var \Psr\Http\Message\ResponseInterface $response */
            $response = $this->client->request('get', $uri, ['connect_timeout' => $this->connectTimeout]);
        } catch (\GuzzleHttp\Exception\GuzzleException $e) {
            throw new FetcherException(
                sprintf(
                    'an error occured while fetching remote data from URI %s',
                    $uri
                ),
                0,
                $e
            );
        }

        if (200 !== $response->getStatusCode()) {
            throw new FetcherException(
                sprintf(
                    'an error occured while fetching remote data from URI %s: StatusCode was %d',
                    $uri,
                    $response->getStatusCode()
                )
            );
        }

        try {
            $content = $response->getBody()->getContents();
        } catch (\Exception $e) {
            throw new FetcherException('an error occured while fetching remote data', 0, $e);
        }

        if (empty($content)) {
            $error = error_get_last();

            throw FetcherException::httpError($uri, $error['message'] ?? '');
        }

        $this->logger->debug('finished fetching remote file');
        $this->logger->debug('started updating cache from remote file');

        $converter = new Converter($this->logger, $this->cache);
        $this->storeContent($converter, $content, $cachedVersion);

        $this->logger->debug('finished updating cache from remote file');
    }
public function update ( string $ remoteFile = IniLoaderInterface :: PHP_INI ) : void { $ this -> logger -> debug ( 'started fetching remote file' ) ; try { $ cachedVersion = $ this -> checkUpdate ( ) ; } catch ( NoNewVersionException $ e ) { return ; } catch ( NoCachedVersionException $ e ) { $ cachedVersion = 0 ; } $ loader = new IniLoader ( ) ; $ loader -> setRemoteFilename ( $ remoteFile ) ; $ uri = $ loader -> getRemoteIniUrl ( ) ; try { /** @var \Psr\Http\Message\ResponseInterface $response */ $ response = $ this -> client -> request ( 'get' , $ uri , [ 'connect_timeout' => $ this -> connectTimeout ] ) ; } catch ( \ GuzzleHttp \ Exception \ GuzzleException $ e ) { throw new FetcherException ( sprintf ( 'an error occured while fetching remote data from URI %s' , $ uri ) , 0 , $ e ) ; } if ( 200 !== $ response -> getStatusCode ( ) ) { throw new FetcherException ( sprintf ( 'an error occured while fetching remote data from URI %s: StatusCode was %d' , $ uri , $ response -> getStatusCode ( ) ) ) ; } try { $ content = $ response -> getBody ( ) -> getContents ( ) ; } catch ( \ Exception $ e ) { throw new FetcherException ( 'an error occured while fetching remote data' , 0 , $ e ) ; } if ( empty ( $ content ) ) { $ error = error_get_last ( ) ; throw FetcherException :: httpError ( $ uri , $ error [ 'message' ] ?? '' ) ; } $ this -> logger -> debug ( 'finished fetching remote file' ) ; $ this -> logger -> debug ( 'started updating cache from remote file' ) ; $ converter = new Converter ( $ this -> logger , $ this -> cache ) ; $ this -> storeContent ( $ converter , $ content , $ cachedVersion ) ; $ this -> logger -> debug ( 'finished updating cache from remote file' ) ; }
fetches a remote file, parses it and writes the result into the cache
if the local stored information are in the same version as the remote data no actions are
taken

@param string $remoteFile The code for the remote file to load

@throws \BrowscapPHP\Exception\FetcherException
@throws \BrowscapPHP\Helper\Exception
@throws \BrowscapPHP\Exception\ErrorCachedVersionException
fetches a remote file parses it and writes the result into the cache if the local stored information are in the same version as the remote data no actions are taken