3 namespace Alchemy\Zippy\Resource\Reader\Guzzle;
5 use Alchemy\Zippy\Resource\Resource as ZippyResource;
6 use Alchemy\Zippy\Resource\ResourceReader;
7 use Guzzle\Http\Client;
8 use Guzzle\Http\ClientInterface;
9 use Guzzle\Http\EntityBodyInterface;
11 class LegacyGuzzleReader implements ResourceReader
14 * @var ClientInterface
19 * @var \Alchemy\Zippy\Resource\Resource $resource
24 * This is necessary to prevent the underlying PHP stream from being destroyed
25 * @link https://github.com/guzzle/guzzle/issues/366#issuecomment-20295409
26 * @var EntityBodyInterface|null
28 private $stream = null;
31 * @param ZippyResource $resource
32 * @param ClientInterface $client
34 public function __construct(ZippyResource $resource, ClientInterface $client = null)
36 $this->client = $client ?: new Client();
37 $this->resource = $resource;
43 public function getContents()
45 return $this->buildRequest()->send()->getBody(true);
51 public function getContentsAsStream()
54 $this->stream = $this->buildRequest()->send()->getBody(false);
57 return $this->stream->getStream();
61 * @return \Guzzle\Http\Message\RequestInterface
63 private function buildRequest()
65 return $this->client->get($this->resource->getOriginal());