Skip to content

Commit

Permalink
Merge pull request #44 from M6Web/feature/refactor-client
Browse files Browse the repository at this point in the history
use the property accessor from the container
  • Loading branch information
omansour committed Oct 27, 2015
2 parents b70415e + 48143c3 commit 4cc5247
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/DependencyInjection/M6WebStatsdExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\PropertyAccess;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\Config\FileLocator;

/**
* This is the class that loads and manages your bundle configuration
Expand All @@ -27,6 +28,9 @@ public function load(array $configs, ContainerBuilder $container)
$servers = isset($config['servers']) ? $config['servers'] : [];
$clients = isset($config['clients']) ? $config['clients'] : [];

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');

$clientServiceNames = [];
foreach ($clients as $alias => $clientConfig) {
// load client in the container
Expand Down Expand Up @@ -161,7 +165,7 @@ protected function loadClient($container, $alias, array $config, array $servers,
$definition->addMethodCall('addEventToListen', [$eventName, $eventConfig]);
}

$definition->addMethodCall('setPropertyAccessor', [PropertyAccess\PropertyAccess::createPropertyAccessorBuilder()->enableMagicCall()->getPropertyAccessor()]);
$definition->addMethodCall('setPropertyAccessor', [new Reference('property_accessor_statsdbundle')]);

$container->setDefinition($serviceId, $definition);

Expand Down
8 changes: 8 additions & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameters:
property_accessor.class_statsdbundle: Symfony\Component\PropertyAccess\PropertyAccessor

services:
property_accessor_statsdbundle:
public: false
class: %property_accessor.class_statsdbundle%
arguments: [true] # magical => true
8 changes: 1 addition & 7 deletions src/Tests/Units/DependencyInjection/M6WebStatsdExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@

class M6WebStatsdExtension extends atoum\test
{
/**
* @var BaseM6WebStatsdExtension
*/
protected $extension;

/**
* @var ContainerBuilder
Expand All @@ -23,11 +19,9 @@ class M6WebStatsdExtension extends atoum\test

protected function initContainer($resource, $debug = false)
{
$this->extension = new BaseM6WebStatsdExtension();

$this->container = new ContainerBuilder();
$this->container->register('event_dispatcher', new EventDispatcher());
$this->container->registerExtension($this->extension);
$this->container->registerExtension(new BaseM6WebStatsdExtension());

$this->loadConfiguration($this->container, $resource);

Expand Down

0 comments on commit 4cc5247

Please sign in to comment.