Skip to content

Commit 9913d9c

Browse files
committed
minor #514 Fix typo, invalid definition and add missing condition to check (HypeMC)
This PR was merged into the 3.x-dev branch. Discussion ---------- Fix typo, invalid definition and add missing condition to check A few minor issues I noticed while working on some other PRs. Commits ------- e2d05df Fix typo, invalid definition and add missing condition to check
2 parents 58b98dc + e2d05df commit 9913d9c

File tree

4 files changed

+48
-38
lines changed

4 files changed

+48
-38
lines changed

DependencyInjection/Configuration.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ public function getConfigTreeBuilder(): TreeBuilder
534534
->scalarNode('max_level')->defaultValue('EMERGENCY')->end() // filter
535535
->scalarNode('buffer_size')->defaultValue(0)->end() // fingers_crossed and buffer
536536
->booleanNode('flush_on_overflow')->defaultFalse()->end() // buffer
537-
->scalarNode('handler')->end() // fingers_crossed and buffer
537+
->scalarNode('handler')->end() // fingers_crossed, buffer, filter, deduplication, sampling
538538
->scalarNode('url')->end() // cube
539539
->scalarNode('exchange')->end() // amqp
540540
->scalarNode('exchange_name')->defaultValue('log')->end() // amqp
@@ -658,8 +658,8 @@ public function getConfigTreeBuilder(): TreeBuilder
658658
->thenInvalid('Service handlers can not have a formatter configured in the bundle, you must reconfigure the service itself instead')
659659
->end()
660660
->validate()
661-
->ifTrue(function ($v) { return ('fingers_crossed' === $v['type'] || 'buffer' === $v['type'] || 'filter' === $v['type'] || 'sampling' === $v['type']) && empty($v['handler']); })
662-
->thenInvalid('The handler has to be specified to use a FingersCrossedHandler or BufferHandler or FilterHandler or SamplingHandler')
661+
->ifTrue(function ($v) { return \in_array($v['type'], ['fingers_crossed', 'buffer', 'filter', 'deduplication', 'sampling'], true) && empty($v['handler']); })
662+
->thenInvalid('The handler has to be specified to use a FingersCrossedHandler, BufferHandler, FilterHandler, DeduplicationHandler or SamplingHandler')
663663
->end()
664664
->validate()
665665
->ifTrue(function ($v) { return 'fingers_crossed' === $v['type'] && !empty($v['excluded_404s']) && !empty($v['activation_strategy']); })
@@ -801,9 +801,9 @@ public function getConfigTreeBuilder(): TreeBuilder
801801
return $treeBuilder;
802802
}
803803

804-
private function addGelfSection(ArrayNodeDefinition $handerNode)
804+
private function addGelfSection(ArrayNodeDefinition $handlerNode)
805805
{
806-
$handerNode
806+
$handlerNode
807807
->children()
808808
->arrayNode('publisher')
809809
->canBeUnset()
@@ -832,9 +832,9 @@ private function addGelfSection(ArrayNodeDefinition $handerNode)
832832
;
833833
}
834834

835-
private function addMongoSection(ArrayNodeDefinition $handerNode)
835+
private function addMongoSection(ArrayNodeDefinition $handlerNode)
836836
{
837-
$handerNode
837+
$handlerNode
838838
->children()
839839
->arrayNode('mongo')
840840
->canBeUnset()
@@ -872,9 +872,9 @@ private function addMongoSection(ArrayNodeDefinition $handerNode)
872872
;
873873
}
874874

875-
private function addElasticsearchSection(ArrayNodeDefinition $handerNode)
875+
private function addElasticsearchSection(ArrayNodeDefinition $handlerNode)
876876
{
877-
$handerNode
877+
$handlerNode
878878
->children()
879879
->arrayNode('elasticsearch')
880880
->canBeUnset()
@@ -904,9 +904,9 @@ private function addElasticsearchSection(ArrayNodeDefinition $handerNode)
904904
;
905905
}
906906

907-
private function addRedisSection(ArrayNodeDefinition $handerNode)
907+
private function addRedisSection(ArrayNodeDefinition $handlerNode)
908908
{
909-
$handerNode
909+
$handlerNode
910910
->children()
911911
->arrayNode('redis')
912912
->canBeUnset()
@@ -937,9 +937,9 @@ private function addRedisSection(ArrayNodeDefinition $handerNode)
937937
;
938938
}
939939

940-
private function addPredisSection(ArrayNodeDefinition $handerNode)
940+
private function addPredisSection(ArrayNodeDefinition $handlerNode)
941941
{
942-
$handerNode
942+
$handlerNode
943943
->children()
944944
->arrayNode('predis')
945945
->canBeUnset()
@@ -966,9 +966,9 @@ private function addPredisSection(ArrayNodeDefinition $handerNode)
966966
;
967967
}
968968

969-
private function addMailerSection(ArrayNodeDefinition $handerNode)
969+
private function addMailerSection(ArrayNodeDefinition $handlerNode)
970970
{
971-
$handerNode
971+
$handlerNode
972972
->children()
973973
->scalarNode('from_email')->end() // swift_mailer, native_mailer, symfony_mailer and flowdock
974974
->arrayNode('to_email') // swift_mailer, native_mailer and symfony_mailer
@@ -1013,9 +1013,9 @@ private function addMailerSection(ArrayNodeDefinition $handerNode)
10131013
;
10141014
}
10151015

1016-
private function addVerbosityLevelSection(ArrayNodeDefinition $handerNode)
1016+
private function addVerbosityLevelSection(ArrayNodeDefinition $handlerNode)
10171017
{
1018-
$handerNode
1018+
$handlerNode
10191019
->children()
10201020
->arrayNode('verbosity_levels') // console
10211021
->beforeNormalization()
@@ -1073,9 +1073,9 @@ private function addVerbosityLevelSection(ArrayNodeDefinition $handerNode)
10731073
;
10741074
}
10751075

1076-
private function addChannelsSection(ArrayNodeDefinition $handerNode)
1076+
private function addChannelsSection(ArrayNodeDefinition $handlerNode)
10771077
{
1078-
$handerNode
1078+
$handlerNode
10791079
->children()
10801080
->arrayNode('channels')
10811081
->fixXmlConfig('channel', 'elements')

DependencyInjection/MonologExtension.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
724724

725725
case 'sentry':
726726
if (null !== $handler['hub_id']) {
727-
$hub = new Reference($handler['hub_id']);
727+
$hubId = $handler['hub_id'];
728728
} else {
729729
if (null !== $handler['client_id']) {
730730
$clientId = $handler['client_id'];
@@ -755,18 +755,18 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
755755
}
756756
}
757757

758-
$hub = new Definition(
758+
$hubId = \sprintf('monolog.handler.%s.hub', $name);
759+
$hub = $container->setDefinition($hubId, new Definition(
759760
'Sentry\\State\\Hub',
760761
[new Reference($clientId)]
761-
);
762-
$container->setDefinition(\sprintf('monolog.handler.%s.hub', $name), $hub);
762+
));
763763

764764
// can't set the hub to the current hub, getting into a recursion otherwise...
765765
// $hub->addMethodCall('setCurrent', array($hub));
766766
}
767767

768768
$definition->setArguments([
769-
$hub,
769+
new Reference($hubId),
770770
$handler['level'],
771771
$handler['bubble'],
772772
$handler['fill_extra_context'],

Tests/DependencyInjection/MonologExtensionTest.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,10 @@ public function testRavenHandlerWhenAClientIsSpecified()
371371

372372
public function testSentryHandlerWhenConfigurationIsWrong()
373373
{
374-
try {
375-
$this->getContainer([['handlers' => ['sentry' => ['type' => 'sentry']]]]);
376-
$this->fail();
377-
} catch (InvalidConfigurationException $e) {
378-
$this->assertStringContainsString('DSN', $e->getMessage());
379-
}
374+
$this->expectException(InvalidConfigurationException::class);
375+
$this->expectExceptionMessage('The DSN has to be specified to use Sentry\'s handler');
376+
377+
$this->getContainer([['handlers' => ['sentry' => ['type' => 'sentry']]]]);
380378
}
381379

382380
public function testSentryHandlerWhenADSNIsSpecified()
@@ -396,8 +394,9 @@ public function testSentryHandlerWhenADSNIsSpecified()
396394

397395
$handler = $container->getDefinition('monolog.handler.sentry');
398396
$this->assertDICDefinitionClass($handler, 'Sentry\Monolog\Handler');
397+
$this->assertDICConstructorArguments($handler, [new Reference('monolog.handler.sentry.hub'), 'DEBUG', true, false]);
399398

400-
$hub = $container->getDefinition('monolog.handler.sentry.hub');
399+
$hub = $container->getDefinition($handler->getArguments()[0]);
401400
$this->assertDICDefinitionClass($hub, 'Sentry\State\Hub');
402401
$this->assertDICConstructorArguments($hub, [new Reference('monolog.sentry.client.'.sha1($dsn))]);
403402
}
@@ -426,7 +425,12 @@ public function testSentryHandlerWhenADSNAndAClientAreSpecified()
426425
$this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', [new Reference('monolog.handler.sentry')]);
427426

428427
$handler = $container->getDefinition('monolog.handler.sentry');
429-
$this->assertDICConstructorArguments($handler->getArguments()[0], [new Reference('sentry.client')]);
428+
$this->assertDICDefinitionClass($handler, 'Sentry\Monolog\Handler');
429+
$this->assertDICConstructorArguments($handler, [new Reference('monolog.handler.sentry.hub'), 'DEBUG', true, false]);
430+
431+
$hub = $container->getDefinition($handler->getArguments()[0]);
432+
$this->assertDICDefinitionClass($hub, 'Sentry\State\Hub');
433+
$this->assertDICConstructorArguments($hub, [new Reference('sentry.client')]);
430434
}
431435

432436
public function testSentryHandlerWhenAClientIsSpecified()
@@ -452,7 +456,12 @@ public function testSentryHandlerWhenAClientIsSpecified()
452456
$this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', [new Reference('monolog.handler.sentry')]);
453457

454458
$handler = $container->getDefinition('monolog.handler.sentry');
455-
$this->assertDICConstructorArguments($handler->getArguments()[0], [new Reference('sentry.client')]);
459+
$this->assertDICDefinitionClass($handler, 'Sentry\Monolog\Handler');
460+
$this->assertDICConstructorArguments($handler, [new Reference('monolog.handler.sentry.hub'), 'DEBUG', true, false]);
461+
462+
$hub = $container->getDefinition($handler->getArguments()[0]);
463+
$this->assertDICDefinitionClass($hub, 'Sentry\State\Hub');
464+
$this->assertDICConstructorArguments($hub, [new Reference('sentry.client')]);
456465
}
457466

458467
public function testSentryHandlerWhenAHubIsSpecified()
@@ -478,6 +487,7 @@ public function testSentryHandlerWhenAHubIsSpecified()
478487
$this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', [new Reference('monolog.handler.sentry')]);
479488

480489
$handler = $container->getDefinition('monolog.handler.sentry');
490+
$this->assertDICDefinitionClass($handler, 'Sentry\Monolog\Handler');
481491
$this->assertDICConstructorArguments($handler, [new Reference('sentry.hub'), 'DEBUG', true, false]);
482492
}
483493

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
],
1818
"require": {
1919
"php": ">=7.2.5",
20-
"symfony/monolog-bridge": "^5.4 || ^6.0 || ^7.0",
21-
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
20+
"monolog/monolog": "^1.25.1 || ^2.0 || ^3.0",
2221
"symfony/config": "^5.4 || ^6.0 || ^7.0",
22+
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
2323
"symfony/http-kernel": "^5.4 || ^6.0 || ^7.0",
24-
"monolog/monolog": "^1.25.1 || ^2.0 || ^3.0"
24+
"symfony/monolog-bridge": "^5.4 || ^6.0 || ^7.0"
2525
},
2626
"require-dev": {
27-
"symfony/yaml": "^5.4 || ^6.0 || ^7.0",
2827
"symfony/console": "^5.4 || ^6.0 || ^7.0",
29-
"symfony/phpunit-bridge": "^7.1"
28+
"symfony/phpunit-bridge": "^7.1",
29+
"symfony/yaml": "^5.4 || ^6.0 || ^7.0"
3030
},
3131
"autoload": {
3232
"psr-4": { "Symfony\\Bundle\\MonologBundle\\": "" },

0 commit comments

Comments
 (0)