Skip to content
This repository has been archived by the owner on Jul 15, 2021. It is now read-only.

Commit

Permalink
Merge pull request #33 from csarrazi/deprecate-client-factory
Browse files Browse the repository at this point in the history
Deprecate client factory
  • Loading branch information
csarrazi committed Jun 5, 2015
2 parents 231145c + 7e29eb5 commit e355ad8
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/DependencyInjection/CompilerPass/SubscriberPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
8 changes: 8 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/CsaGuzzleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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']);
Expand Down
7 changes: 3 additions & 4 deletions src/Factory/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function __construct($class)
{
$this->class = $class;
$this->subscribers = [];
$this->clientOptions = [];
}

/**
Expand All @@ -47,12 +46,12 @@ 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) {
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);
}
}
Expand All @@ -63,7 +62,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;
}
}
2 changes: 1 addition & 1 deletion src/Factory/DescriptionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getDescription($alias)
*/
public function loadDescriptions()
{
if ($this->descriptions) {
if (!empty($this->descriptions)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/GuzzleHttp/Subscriber/CacheSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
11 changes: 11 additions & 0 deletions src/Tests/DependencyInjection/CsaGuzzleExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ public function testLegacyCacheConfiguration()
$this->assertSame('my.service.id', (string)$container->getDefinition((string) $alias)->getArgument(0));
}

public function testLegacyFactoryConfiguration()
{
$yaml = <<<YAML
factory_class: GuzzleHttp\Client
YAML;

$container = $this->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
Expand Down
3 changes: 1 addition & 2 deletions src/Tests/GuzzleHttp/Subscriber/CacheSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e355ad8

Please sign in to comment.