From 95c681a3205459acbfff02e850d18d239019aced Mon Sep 17 00:00:00 2001 From: Charles Sarrazin Date: Fri, 5 Jun 2015 09:17:56 +0200 Subject: [PATCH 1/2] Deprecating client factory --- .../CompilerPass/SubscriberPass.php | 2 +- src/DependencyInjection/Configuration.php | 8 ++++++++ src/DependencyInjection/CsaGuzzleExtension.php | 4 ++-- src/Factory/ClientFactory.php | 4 ++-- .../DependencyInjection/CsaGuzzleExtensionTest.php | 11 +++++++++++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/DependencyInjection/CompilerPass/SubscriberPass.php b/src/DependencyInjection/CompilerPass/SubscriberPass.php index 5bd2d1e2..e054de45 100644 --- a/src/DependencyInjection/CompilerPass/SubscriberPass.php +++ b/src/DependencyInjection/CompilerPass/SubscriberPass.php @@ -140,7 +140,7 @@ private function createConfigurator(array $subscriberIds) } /** - * @param array $serviceIds + * @param array $subscriberIds * * @return array Subscriber service ids as values & their aliases as keys */ diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 2e1f6e3e..6405833d 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -35,6 +35,14 @@ public function getConfigTreeBuilder() $rootNode = $treeBuilder->root('csa_guzzle'); $rootNode + ->beforeNormalization() + ->ifTrue(function ($v) { + return isset($v['factory_class']); + }) + ->then(function ($v) { + trigger_error('The ClientFactory class is deprecated since version 1.3 and will be removed in 2.0. Use the \'csa_guzzle.client\' tag instead', E_USER_DEPRECATED); + }) + ->end() ->fixXmlConfig('client') ->children() ->arrayNode('profiler') diff --git a/src/DependencyInjection/CsaGuzzleExtension.php b/src/DependencyInjection/CsaGuzzleExtension.php index e0ca69eb..4c44243b 100644 --- a/src/DependencyInjection/CsaGuzzleExtension.php +++ b/src/DependencyInjection/CsaGuzzleExtension.php @@ -71,7 +71,7 @@ public function load(array $configs, ContainerBuilder $container) $definition = $container->getDefinition('csa_guzzle.client_factory'); $definition->replaceArgument(0, $config['factory_class']); - $this->processClientsConfiguration($config, $container, $definition, $descriptionFactory); + $this->processClientsConfiguration($config, $container, $descriptionFactory); } private function processCacheConfiguration(array $config, ContainerBuilder $container) @@ -94,7 +94,7 @@ private function processCacheConfiguration(array $config, ContainerBuilder $cont $container->setAlias('csa_guzzle.default_cache_adapter', $adapterId); } - private function processClientsConfiguration(array $config, ContainerBuilder $container, Definition $clientFactory, Definition $descriptionFactory) + private function processClientsConfiguration(array $config, ContainerBuilder $container, Definition $descriptionFactory) { foreach ($config['clients'] as $name => $options) { $client = new Definition($config['factory_class']); diff --git a/src/Factory/ClientFactory.php b/src/Factory/ClientFactory.php index 6b907942..f8d8dd1a 100644 --- a/src/Factory/ClientFactory.php +++ b/src/Factory/ClientFactory.php @@ -47,7 +47,7 @@ public function __construct($class) */ public function create(array $options = [], array $subscribers = []) { - trigger_error('The ClientFactory class is deprecated since version 1.3 and will be removed in 2.0. Use the \`csa_guzzle.client\` tag instead', E_USER_DEPRECATED); + trigger_error('The ClientFactory class is deprecated since version 1.3 and will be removed in 2.0. Use the \'csa_guzzle.client\' tag instead', E_USER_DEPRECATED); $client = new $this->class($options); if ($client instanceof HasEmitterInterface) { @@ -63,7 +63,7 @@ public function create(array $options = [], array $subscribers = []) public function registerSubscriber($name, SubscriberInterface $subscriber) { - trigger_error('The ClientFactory class is deprecated since version 1.3 and will be removed in 2.0. Use the \`csa_guzzle.client\` tag instead', E_USER_DEPRECATED); + trigger_error('The ClientFactory class is deprecated since version 1.3 and will be removed in 2.0. Use the \'csa_guzzle.client\' tag instead', E_USER_DEPRECATED); $this->subscribers[$name] = $subscriber; } } diff --git a/src/Tests/DependencyInjection/CsaGuzzleExtensionTest.php b/src/Tests/DependencyInjection/CsaGuzzleExtensionTest.php index 80167f89..656b0953 100644 --- a/src/Tests/DependencyInjection/CsaGuzzleExtensionTest.php +++ b/src/Tests/DependencyInjection/CsaGuzzleExtensionTest.php @@ -149,6 +149,17 @@ public function testLegacyCacheConfiguration() $this->assertSame('my.service.id', (string)$container->getDefinition((string) $alias)->getArgument(0)); } + public function testLegacyFactoryConfiguration() + { + $yaml = <<createContainer($yaml); + $factory = $container->getDefinition('csa_guzzle.client_factory'); + $this->assertSame('GuzzleHttp\Client', $factory->getArgument(0)); + } + /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException * @expectedExceptionMessage Invalid configuration for path "csa_guzzle.cache.adapter.type": Invalid cache adapter From 7e29eb5f60925c87214ae3b36ff47142cdc74e82 Mon Sep 17 00:00:00 2001 From: Charles Sarrazin Date: Fri, 5 Jun 2015 09:32:35 +0200 Subject: [PATCH 2/2] Fixed issue with request transfer info being injected for no reason --- src/Factory/ClientFactory.php | 3 +-- src/Factory/DescriptionFactory.php | 2 +- src/GuzzleHttp/Subscriber/CacheSubscriber.php | 2 +- src/Tests/GuzzleHttp/Subscriber/CacheSubscriberTest.php | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Factory/ClientFactory.php b/src/Factory/ClientFactory.php index f8d8dd1a..3c8b45c3 100644 --- a/src/Factory/ClientFactory.php +++ b/src/Factory/ClientFactory.php @@ -34,7 +34,6 @@ public function __construct($class) { $this->class = $class; $this->subscribers = []; - $this->clientOptions = []; } /** @@ -52,7 +51,7 @@ public function create(array $options = [], array $subscribers = []) if ($client instanceof HasEmitterInterface) { foreach ($this->subscribers as $name => $subscriber) { - if (!$subscribers || (isset($subscribers[$name]) && $subscribers[$name])) { + if (empty($subscribers) || (isset($subscribers[$name]) && $subscribers[$name])) { $client->getEmitter()->attach($subscriber); } } diff --git a/src/Factory/DescriptionFactory.php b/src/Factory/DescriptionFactory.php index 30a25ca4..90a104ff 100644 --- a/src/Factory/DescriptionFactory.php +++ b/src/Factory/DescriptionFactory.php @@ -48,7 +48,7 @@ public function getDescription($alias) */ public function loadDescriptions() { - if ($this->descriptions) { + if (!empty($this->descriptions)) { return; } diff --git a/src/GuzzleHttp/Subscriber/CacheSubscriber.php b/src/GuzzleHttp/Subscriber/CacheSubscriber.php index 9f4997c2..bd4c2ea7 100644 --- a/src/GuzzleHttp/Subscriber/CacheSubscriber.php +++ b/src/GuzzleHttp/Subscriber/CacheSubscriber.php @@ -57,6 +57,6 @@ public function onBefore(BeforeEvent $event) public function onComplete(CompleteEvent $event) { - $this->storage->save($event->getRequest(), $event->getResponse(), $event->getTransferInfo()); + $this->storage->save($event->getRequest(), $event->getResponse()); } } diff --git a/src/Tests/GuzzleHttp/Subscriber/CacheSubscriberTest.php b/src/Tests/GuzzleHttp/Subscriber/CacheSubscriberTest.php index 08232ae6..842518f5 100644 --- a/src/Tests/GuzzleHttp/Subscriber/CacheSubscriberTest.php +++ b/src/Tests/GuzzleHttp/Subscriber/CacheSubscriberTest.php @@ -36,8 +36,7 @@ public function testFetch() ->method('save') ->with( $this->isInstanceOf('GuzzleHttp\Message\RequestInterface'), - $this->equalTo($response), - $this->isType('array') + $this->equalTo($response) ) ; $adapter