Skip to content

Commit c9be2a1

Browse files
committed
minor #95 Do not require raven.dsn when a client_id is specified (lyrixx)
This PR was merged into the 2.6.x-dev branch. Discussion ---------- Do not require raven.dsn when a client_id is specified Right now, I have the following configuration. And as you can see, the raven.dsn is useless here, are the client_id service is not buildt by the extension but by myself. ```yml monolog: handlers: raven: type: raven # useless, because we set-up a custom client, but we have to... dsn: "%raven.dsn%" client_id: sensiolabs.toolkit.monolog.raven_client ``` So with with patch, we can use: ```yml monolog: handlers: raven: type: raven client_id: sensiolabs.toolkit.monolog.raven_client ``` BTW, I don't know the target branch of this PR. Commits ------- 55aaefd Do not require raven.dsn when a client_id is specified
2 parents df24297 + 55aaefd commit c9be2a1

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ public function getConfigTreeBuilder()
570570
->thenInvalid('The token and user have to be specified to use a PushoverHandler')
571571
->end()
572572
->validate()
573-
->ifTrue(function ($v) { return 'raven' === $v['type'] && !array_key_exists('dsn', $v); })
573+
->ifTrue(function ($v) { return 'raven' === $v['type'] && !array_key_exists('dsn', $v) && null === $v['client_id']; })
574574
->thenInvalid('The DSN has to be specified to use a RavenHandler')
575575
->end()
576576
->validate()

DependencyInjection/MonologExtension.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,15 +468,14 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
468468
break;
469469

470470
case 'raven':
471-
$clientId = 'monolog.raven.client.' . sha1($handler['dsn']);
472471
if (null !== $handler['client_id']) {
473472
$clientId = $handler['client_id'];
474-
}
475-
if (!$container->hasDefinition($clientId)) {
473+
} else {
476474
$client = new Definition("Raven_Client", array(
477475
$handler['dsn']
478476
));
479477
$client->setPublic(false);
478+
$clientId = 'monolog.raven.client.'.sha1($handler['dsn']);
480479
$container->setDefinition($clientId, $client);
481480
}
482481
$definition->setArguments(array(

Tests/DependencyInjection/MonologExtensionTest.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,19 @@ public function testSocketHandler()
210210

211211
}
212212

213-
public function testRavenHandler()
213+
public function testRavenHandlerWhenConfigurationIsWrong()
214214
{
215-
$dsn = 'http://43f6017361224d098402974103bfc53d:[email protected]:9000/1';
216-
217215
try {
218216
$this->getContainer(array(array('handlers' => array('raven' => array('type' => 'raven')))));
219217
$this->fail();
220218
} catch (InvalidConfigurationException $e) {
221219
$this->assertContains('DSN', $e->getMessage());
222220
}
221+
}
222+
223+
public function testRavenHandlerWhenADSNIsSpecified()
224+
{
225+
$dsn = 'http://43f6017361224d098402974103bfc53d:[email protected]:9000/1';
223226

224227
$container = $this->getContainer(array(array('handlers' => array('raven' => array(
225228
'type' => 'raven', 'dsn' => $dsn)
@@ -234,15 +237,36 @@ public function testRavenHandler()
234237

235238
$handler = $container->getDefinition('monolog.handler.raven');
236239
$this->assertDICDefinitionClass($handler, '%monolog.handler.raven.class%');
240+
}
237241

242+
public function testRavenHandlerWhenADSNAndAClientAreSpecified()
243+
{
238244
$container = $this->getContainer(array(array('handlers' => array('raven' => array(
239-
'type' => 'raven', 'dsn' => $dsn, 'client_id' => 'raven.client')
245+
'type' => 'raven', 'dsn' => 'foobar', 'client_id' => 'raven.client')
240246
))));
241247

242-
$this->assertTrue($container->hasDefinition('raven.client'));
248+
$this->assertFalse($container->hasDefinition('raven.client'));
249+
250+
$logger = $container->getDefinition('monolog.logger');
251+
$this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.raven')));
243252

244-
$handler = $container->getDefinition('raven.client');
245-
$this->assertDICDefinitionClass($handler, 'Raven_Client');
253+
$handler = $container->getDefinition('monolog.handler.raven');
254+
$this->assertDICConstructorArguments($handler, array(new Reference('raven.client'), 100, true));
255+
}
256+
257+
public function testRavenHandlerWhenAClientIsSpecified()
258+
{
259+
$container = $this->getContainer(array(array('handlers' => array('raven' => array(
260+
'type' => 'raven', 'client_id' => 'raven.client')
261+
))));
262+
263+
$this->assertFalse($container->hasDefinition('raven.client'));
264+
265+
$logger = $container->getDefinition('monolog.logger');
266+
$this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.raven')));
267+
268+
$handler = $container->getDefinition('monolog.handler.raven');
269+
$this->assertDICConstructorArguments($handler, array(new Reference('raven.client'), 100, true));
246270
}
247271

248272
public function testLogglyHandler()

0 commit comments

Comments
 (0)