Skip to content

Instantly share code, notes, and snippets.

@morozov
Created June 11, 2014 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morozov/5c47a4438efaf83ee674 to your computer and use it in GitHub Desktop.
Save morozov/5c47a4438efaf83ee674 to your computer and use it in GitHub Desktop.
Proxy Switcher decorator for Guzzle loader
<?php
use Guzzle\Http\ClientInterface;
use Valera\Loader\LoaderInterface;
use Valera\Resource;
use Valera\Loader\Result;
class ProxySwitcher implements LoaderInterface
{
/**
* @var Valera\Loader\LoaderInterface
*/
private $loader;
/**
* @var Guzzle\Http\ClientInterface
*/
private $client;
public function __construct(LoaderInterface $loader, ClientInterface $client)
{
$this->loader = $loader;
$this->client = $client;
}
public function load(Resource $resource, Result $result)
{
$config = $this->getConfig();
$this->client->setConfig($config);
$this->loader->load($resource, $result);
}
}
$guzzle = new Guzzle\Http\Client();
$loader = new Valera\Loader\Guzzle($guzzle);
$proxy = new ProxySwitcher($loader, $guzzle);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment