public function get(string $path, array $headers = [], $cache = true): Response
    {
        if (null === $this->endpoint) {
            return new Response([]);
        }
        $headers[] = 'Package-Session: '.$this->sess;
        $url = $this->endpoint.'/'.ltrim($path, '/');
        $cacheKey = $cache ? ltrim($path, '/') : '';

        if ($cacheKey && $contents = $this->cache->read($cacheKey)) {
            $cachedResponse = Response::fromJson(json_decode($contents, true));
            if ($lastModified = $cachedResponse->getHeader('last-modified')) {
                $response = $this->fetchFileIfLastModified($url, $cacheKey, $lastModified, $headers);
                if (304 === $response->getStatusCode()) {
                    $response = new Response($cachedResponse->getBody(), $response->getOrigHeaders(), 304);
                }

                return $response;
            }
        }

        return $this->fetchFile($url, $cacheKey, $headers);
    }
public function get(string $path, array $headers = [], $cache = true): Response
    {
        if (null === $this->endpoint) {
            return new Response([]);
        }
        $headers[] = 'Package-Session: '.$this->sess;
        $url = $this->endpoint.'/'.ltrim($path, '/');
        $cacheKey = $cache ? ltrim($path, '/') : '';

        if ($cacheKey && $contents = $this->cache->read($cacheKey)) {
            $cachedResponse = Response::fromJson(json_decode($contents, true));
            if ($lastModified = $cachedResponse->getHeader('last-modified')) {
                $response = $this->fetchFileIfLastModified($url, $cacheKey, $lastModified, $headers);
                if (304 === $response->getStatusCode()) {
                    $response = new Response($cachedResponse->getBody(), $response->getOrigHeaders(), 304);
                }

                return $response;
            }
        }

        return $this->fetchFile($url, $cacheKey, $headers);
    }
public function get ( string $ path , array $ headers = [ ] , $ cache = true ) : Response { if ( null === $ this -> endpoint ) { return new Response ( [ ] ) ; } $ headers [ ] = 'Package-Session: ' . $ this -> sess ; $ url = $ this -> endpoint . '/' . ltrim ( $ path , '/' ) ; $ cacheKey = $ cache ? ltrim ( $ path , '/' ) : '' ; if ( $ cacheKey && $ contents = $ this -> cache -> read ( $ cacheKey ) ) { $ cachedResponse = Response :: fromJson ( json_decode ( $ contents , true ) ) ; if ( $ lastModified = $ cachedResponse -> getHeader ( 'last-modified' ) ) { $ response = $ this -> fetchFileIfLastModified ( $ url , $ cacheKey , $ lastModified , $ headers ) ; if ( 304 === $ response -> getStatusCode ( ) ) { $ response = new Response ( $ cachedResponse -> getBody ( ) , $ response -> getOrigHeaders ( ) , 304 ) ; } return $ response ; } } return $ this -> fetchFile ( $ url , $ cacheKey , $ headers ) ; }
Decodes a JSON HTTP response body.

@param string $path    The path to get on the server
@param array  $headers An array of HTTP headers
Decodes a JSON HTTP response body .