Skip to content

Commit

Permalink
Merge pull request #29 from M6Web/feature/service-definition-scope-pr…
Browse files Browse the repository at this point in the history
…ototype

Add scope prototype config option
  • Loading branch information
lnahiro committed Jan 11, 2016
2 parents 4217ee8 + 1cd6ab8 commit 5db49e7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/AmqpBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function getConfigTreeBuilder()
->children()
->booleanNode('debug')->defaultValue('%kernel.debug%')->end()
->booleanNode('event_dispatcher')->defaultTrue()->end()
->booleanNode('prototype')->defaultFalse()->end()
->end();

$this->addConnections($rootNode);
Expand Down
12 changes: 12 additions & 0 deletions src/AmqpBundle/DependencyInjection/M6WebAmqpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ protected function loadConnections(ContainerBuilder $container, array $config)

$connectionDefinition->setArguments([['heartbeat' => $connection['heartbeat']]]);

if ($config['prototype']) {
$connectionDefinition->setScope('prototype');
}

if (!$connection['lazy']) {
$connectionDefinition->addMethodCall('connect');
}
Expand Down Expand Up @@ -102,6 +106,10 @@ protected function loadProducers(ContainerBuilder $container, array $config)
$producerDefinition->setFactoryService('m6_web_amqp.producer_factory')
->setFactoryMethod('get');

if ($config['prototype']) {
$producerDefinition->setScope('prototype');
}

if ($lazy) {
if (!method_exists($producerDefinition, 'setLazy')) {
throw new \InvalidArgumentException('It\'s not possible to declare a service as lazy. Are you using Symfony 2.3?');
Expand Down Expand Up @@ -156,6 +164,10 @@ protected function loadConsumers(ContainerBuilder $container, array $config)
$consumerDefinition->setFactoryService('m6_web_amqp.consumer_factory')
->setFactoryMethod('get');

if ($config['prototype']) {
$consumerDefinition->setScope('prototype');
}

if ($lazy) {
if (!method_exists($consumerDefinition, 'setLazy')) {
throw new \InvalidArgumentException('It\'s not possible to declare a service as lazy. Are you using Symfony 2.3?');
Expand Down
1 change: 1 addition & 0 deletions src/AmqpBundle/Tests/Fixtures/queue-arguments-config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
m6_web_amqp:
prototype: true
connections:
default:
host: 'localhost'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public function testQueueArgumentsConfig()
$this
->boolean($container->has('m6_web_amqp.producer.producer_2'))
->isTrue()
->string($container->getDefinition('m6_web_amqp.producer.producer_2')->getScope())
->isEqualTo('prototype')
->array($queueOptions = $container->getDefinition('m6_web_amqp.producer.producer_2')->getArgument(3))
->hasSize(6)
->string($queueOptions['name'])
Expand All @@ -63,6 +65,8 @@ public function testQueueArgumentsConfig()
$this
->boolean($container->has('m6_web_amqp.consumer.consumer_1'))
->isTrue()
->string($container->getDefinition('m6_web_amqp.consumer.consumer_1')->getScope())
->isEqualTo('prototype')
->array($queueOptions = $container->getDefinition('m6_web_amqp.consumer.consumer_1')->getArgument(3))
->hasSize(7)
->string($queueOptions['name'])
Expand Down

0 comments on commit 5db49e7

Please sign in to comment.