Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Commit

Permalink
Check if client method is callable before adding the method call [ci …
Browse files Browse the repository at this point in the history
…skip]
  • Loading branch information
gremo committed May 28, 2016
1 parent 6b577f3 commit 9761afd
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions DependencyInjection/GremoBuzzExtension.php
Expand Up @@ -30,17 +30,18 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('services.xml');

// Set the class parameter based on the client
$container->setParameter(
'gremo_buzz.client.class',
$container->getParameter("gremo_buzz.client.{$config['client']}.class")
);
$clientClass = $container->getParameter("gremo_buzz.client.{$config['client']}.class");
$container->setParameter('gremo_buzz.client.class', $clientClass);

// Get the client definition
// Get the client definition and dynamically add a method calls
$client = $container->getDefinition('gremo_buzz.client');

// Dynamically add a method call to the chosen client
foreach ($config['options'] as $key => $val) {
$client->addMethodCall('set'.implode(array_map('ucfirst', explode('_', $key))), array($val));
$setterMethod = 'set'.implode(array_map('ucfirst', explode('_', $key)));
if (!is_callable(array($clientClass, $setterMethod))) {
continue;
}

$client->addMethodCall($setterMethod, array($val));
}
}
}

0 comments on commit 9761afd

Please sign in to comment.