Skip to content

Commit 23e3c3b

Browse files
committed
Allow marking service handlers as nested
1 parent 8204f3c commit 23e3c3b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

DependencyInjection/MonologExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
131131
if ('service' === $handler['type']) {
132132
$container->setAlias($handlerId, $handler['id']);
133133

134+
if (!empty($handler['nested']) && true === $handler['nested']) {
135+
$this->markNestedHandler($handlerId);
136+
}
137+
134138
return $handlerId;
135139
}
136140

Tests/DependencyInjection/MonologExtensionTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,31 @@ public function testLoadWithServiceHandler()
8484
$this->assertTrue($container->hasDefinition('monolog.logger'));
8585
$this->assertTrue($container->hasAlias('monolog.handler.custom'));
8686

87+
$logger = $container->getDefinition('monolog.logger');
88+
// Custom service handler must be pushed to logger
89+
$this->assertDICDefinitionMethodCallAt(0, $logger, 'useMicrosecondTimestamps', array('%monolog.use_microseconds%'));
90+
$this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', array(new Reference('monolog.handler.custom')));
91+
92+
$handler = $container->findDefinition('monolog.handler.custom');
93+
$this->assertDICDefinitionClass($handler, 'stdClass');
94+
$this->assertDICConstructorArguments($handler, array('foo', false));
95+
}
96+
97+
public function testLoadWithNestedServiceHandler()
98+
{
99+
$container = $this->getContainer(
100+
array(array('handlers' => array('custom' => array('type' => 'service', 'id' => 'some.service.id', 'nested' => true)))),
101+
array('some.service.id' => new Definition('stdClass', array('foo', false)))
102+
);
103+
104+
$this->assertTrue($container->hasDefinition('monolog.logger'));
105+
$this->assertTrue($container->hasAlias('monolog.handler.custom'));
106+
107+
$logger = $container->getDefinition('monolog.logger');
108+
// Nested service handler must not be pushed to logger
109+
$this->assertCount(1, $logger->getMethodCalls());
110+
$this->assertDICDefinitionMethodCallAt(0, $logger, 'useMicrosecondTimestamps', array('%monolog.use_microseconds%'));
111+
87112
$handler = $container->findDefinition('monolog.handler.custom');
88113
$this->assertDICDefinitionClass($handler, 'stdClass');
89114
$this->assertDICConstructorArguments($handler, array('foo', false));

0 commit comments

Comments
 (0)