Skip to content

Commit 6728c60

Browse files
committed
bug #183 Fix service handler usage (avant1)
This PR was squashed before being merged into the 3.x-dev branch (closes #183). Discussion ---------- Fix service handler usage This should fix #181. Commits ------- 2833e61 Fix service handler usage
2 parents df509e8 + 2833e61 commit 6728c60

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

DependencyInjection/MonologExtension.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ public function getNamespace()
129129
private function buildHandler(ContainerBuilder $container, $name, array $handler)
130130
{
131131
$handlerId = $this->getHandlerId($name);
132+
if ('service' === $handler['type']) {
133+
$container->setAlias($handlerId, $handler['id']);
134+
135+
return $handlerId;
136+
}
137+
132138
$definition = new Definition($this->getHandlerClassByType($handler['type']));
133139

134140
$handler['level'] = $this->levelToMonologConst($handler['level']);
@@ -138,11 +144,6 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
138144
}
139145

140146
switch ($handler['type']) {
141-
case 'service':
142-
$container->setAlias($handlerId, $handler['id']);
143-
144-
return $handlerId;
145-
146147
case 'stream':
147148
$definition->setArguments(array(
148149
$handler['path'],

Tests/DependencyInjection/MonologExtensionTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension;
1515
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\Definition;
1718
use Symfony\Component\DependencyInjection\Reference;
1819
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1920

@@ -72,6 +73,21 @@ public function testLoadWithNestedHandler()
7273
$this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, false, 0666));
7374
}
7475

76+
public function testLoadWithServiceHandler()
77+
{
78+
$container = $this->getContainer(
79+
array(array('handlers' => array('custom' => array('type' => 'service', 'id' => 'some.service.id')))),
80+
array('some.service.id' => new Definition('stdClass', array('foo', false)))
81+
);
82+
83+
$this->assertTrue($container->hasDefinition('monolog.logger'));
84+
$this->assertTrue($container->hasAlias('monolog.handler.custom'));
85+
86+
$handler = $container->findDefinition('monolog.handler.custom');
87+
$this->assertDICDefinitionClass($handler, 'stdClass');
88+
$this->assertDICConstructorArguments($handler, array('foo', false));
89+
}
90+
7591
/**
7692
* @expectedException InvalidArgumentException
7793
*/
@@ -365,9 +381,13 @@ public function testFingersCrossedHandlerWhenExcluded404sAreSpecified()
365381
$this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.nested'), new Reference('monolog.handler.main.not_found_strategy'), 0, true, true, null));
366382
}
367383

368-
protected function getContainer(array $config = array())
384+
protected function getContainer(array $config = array(), array $thirdPartyDefinitions = array())
369385
{
370386
$container = new ContainerBuilder();
387+
foreach ($thirdPartyDefinitions as $id => $definition) {
388+
$container->setDefinition($id, $definition);
389+
}
390+
371391
$container->getCompilerPassConfig()->setOptimizationPasses(array());
372392
$container->getCompilerPassConfig()->setRemovingPasses(array());
373393
$container->addCompilerPass(new LoggerChannelPass());

0 commit comments

Comments
 (0)