4 * This file is part of the Behat MinkExtension.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\MinkExtension\ServiceContainer\Driver;
13 use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
14 use Symfony\Component\DependencyInjection\Definition;
17 * @author Christophe Coevoet <stof@notk.org>
19 class GoutteFactory implements DriverFactory
24 public function getDriverName()
32 public function supportsJavascript()
40 public function configure(ArrayNodeDefinition $builder)
44 ->arrayNode('server_parameters')
45 ->useAttributeAsKey('key')
46 ->prototype('variable')->end()
48 ->arrayNode('guzzle_parameters')
49 ->useAttributeAsKey('key')
50 ->prototype('variable')->end()
52 "For Goutte 1.x, these are the second argument of the Guzzle3 client constructor.\n".
53 'For Goutte 2.x, these are the elements passed in the "defaults" key of the Guzzle4 config.'
63 public function buildDriver(array $config)
65 if (!class_exists('Behat\Mink\Driver\GoutteDriver')) {
66 throw new \RuntimeException(
67 'Install MinkGoutteDriver in order to use goutte driver.'
71 if ($this->isGoutte1()) {
72 $guzzleClient = $this->buildGuzzle3Client($config['guzzle_parameters']);
74 $guzzleClient = $this->buildGuzzle4Client($config['guzzle_parameters']);
77 $clientDefinition = new Definition('Behat\Mink\Driver\Goutte\Client', array(
78 $config['server_parameters'],
80 $clientDefinition->addMethodCall('setClient', array($guzzleClient));
82 return new Definition('Behat\Mink\Driver\GoutteDriver', array(
87 private function buildGuzzle4Client(array $parameters)
89 // Force the parameters set by default in Goutte to reproduce its behavior
90 $parameters['allow_redirects'] = false;
91 $parameters['cookies'] = true;
93 return new Definition('GuzzleHttp\Client', array($parameters));
97 private function buildGuzzle3Client(array $parameters)
99 // Force the parameters set by default in Goutte to reproduce its behavior
100 $parameters['redirect.disable'] = true;
102 return new Definition('Guzzle\Http\Client', array(null, $parameters));
105 private function isGoutte1()
107 $refl = new \ReflectionParameter(array('Goutte\Client', 'setClient'), 0);
109 if ($refl->getClass() && 'Guzzle\Http\ClientInterface' === $refl->getClass()->getName()) {