3 namespace Alchemy\Zippy\Resource\Reader\Guzzle;
5 use Alchemy\Zippy\Resource\Resource as ZippyResource;
6 use Alchemy\Zippy\Resource\ResourceReader;
7 use Alchemy\Zippy\Resource\ResourceReaderFactory;
8 use Guzzle\Http\Client;
9 use Guzzle\Http\ClientInterface;
10 use Guzzle\Plugin\Backoff\BackoffPlugin;
11 use Symfony\Component\EventDispatcher\Event;
13 class LegacyGuzzleReaderFactory implements ResourceReaderFactory
16 * @var ClientInterface|null
18 private $client = null;
20 public function __construct(ClientInterface $client = null)
22 $this->client = $client;
25 $this->client = new Client();
27 $this->client->getEventDispatcher()->addListener('request.error', function(Event $event) {
28 // override guzzle default behavior of throwing exceptions
29 // when 4xx & 5xx responses are encountered
30 $event->stopPropagation();
33 $this->client->addSubscriber(BackoffPlugin::getExponentialBackoff(5, array(500, 502, 503, 408)));
38 * @param ZippyResource $resource
39 * @param string $context
41 * @return ResourceReader
43 public function getReader(ZippyResource $resource, $context)
45 return new LegacyGuzzleReader($resource, $this->client);