Merge pull request #236 from Evoke-PHP/master
Fixed guzzle client building for different guzzle versions.
This commit is contained in:
@@ -70,6 +70,8 @@ class GoutteFactory implements DriverFactory
|
|||||||
|
|
||||||
if ($this->isGoutte1()) {
|
if ($this->isGoutte1()) {
|
||||||
$guzzleClient = $this->buildGuzzle3Client($config['guzzle_parameters']);
|
$guzzleClient = $this->buildGuzzle3Client($config['guzzle_parameters']);
|
||||||
|
} elseif ($this->isGuzzle6()) {
|
||||||
|
$guzzleClient = $this->buildGuzzle6Client($config['guzzle_parameters']);
|
||||||
} else {
|
} else {
|
||||||
$guzzleClient = $this->buildGuzzle4Client($config['guzzle_parameters']);
|
$guzzleClient = $this->buildGuzzle4Client($config['guzzle_parameters']);
|
||||||
}
|
}
|
||||||
@@ -84,14 +86,22 @@ class GoutteFactory implements DriverFactory
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildGuzzle4Client(array $parameters)
|
private function buildGuzzle6Client(array $parameters)
|
||||||
{
|
{
|
||||||
// Force the parameters set by default in Goutte to reproduce its behavior
|
// Force the parameters set by default in Goutte to reproduce its behavior
|
||||||
$parameters['allow_redirects'] = false;
|
$parameters['allow_redirects'] = false;
|
||||||
$parameters['cookies'] = true;
|
$parameters['cookies'] = true;
|
||||||
|
|
||||||
return new Definition('GuzzleHttp\Client', array($parameters));
|
return new Definition('GuzzleHttp\Client', array($parameters));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildGuzzle4Client(array $parameters)
|
||||||
|
{
|
||||||
|
// Force the parameters set by default in Goutte to reproduce its behavior
|
||||||
|
$parameters['allow_redirects'] = false;
|
||||||
|
$parameters['cookies'] = true;
|
||||||
|
|
||||||
|
return new Definition('GuzzleHttp\Client', array(array('defaults' => $parameters)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildGuzzle3Client(array $parameters)
|
private function buildGuzzle3Client(array $parameters)
|
||||||
@@ -112,4 +122,10 @@ class GoutteFactory implements DriverFactory
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function isGuzzle6()
|
||||||
|
{
|
||||||
|
return interface_exists('GuzzleHttp\ClientInterface') &&
|
||||||
|
version_compare(\GuzzleHttp\ClientInterface::VERSION, '6.0.0', '>=');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user