Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0934464

Browse filesBrowse files
feature #28176 [DI] [FrameworkBundle] Add LoggerAwareInterface to auto configuration (GaryPEGEOT)
This PR was squashed before being merged into the 4.2-dev branch (closes #28176). Discussion ---------- [DI] [FrameworkBundle] Add LoggerAwareInterface to auto configuration | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Add the method call `setLogger` for every service implementing `Psr\Log\LoggerAwareInterface` Commits ------- afda3c8 [DI] [FrameworkBundle] Add LoggerAwareInterface to auto configuration
2 parents f96753b + afda3c8 commit 0934464
Copy full SHA for 0934464

File tree

Expand file treeCollapse file tree

3 files changed

+22
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+22
-0
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* Allowed configuring PDO-based cache pools via a new `cache.adapter.pdo` abstract service
99
* Deprecated auto-injection of the container in AbstractController instances, register them as service subscribers instead
1010
* Deprecated processing of services tagged `security.expression_language_provider` in favor of a new `AddExpressionLanguageProvidersPass` in SecurityBundle.
11+
* Enabled autoconfiguration for `Psr\Log\LoggerAwareInterface`
1112

1213
4.1.0
1314
-----

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Common\Annotations\AnnotationRegistry;
1515
use Doctrine\Common\Annotations\Reader;
16+
use Psr\Log\LoggerAwareInterface;
1617
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
1718
use Symfony\Bridge\Monolog\Processor\ProcessorInterface;
1819
use Symfony\Bridge\Twig\Extension\CsrfExtension;
@@ -360,6 +361,8 @@ public function load(array $configs, ContainerBuilder $container)
360361
->addTag('messenger.message_handler');
361362
$container->registerForAutoconfiguration(TransportFactoryInterface::class)
362363
->addTag('messenger.transport_factory');
364+
$container->registerForAutoconfiguration(LoggerAwareInterface::class)
365+
->addMethodCall('setLogger', array(new Reference('logger')));
363366

364367
if (!$container->getParameter('kernel.debug')) {
365368
// remove tagged iterator argument for resource checkers

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
1313

1414
use Doctrine\Common\Annotations\Annotation;
15+
use Psr\Log\LoggerAwareInterface;
1516
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
1617
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
1718
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
@@ -26,6 +27,7 @@
2627
use Symfony\Component\Cache\Adapter\RedisAdapter;
2728
use Symfony\Component\DependencyInjection\ChildDefinition;
2829
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
30+
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
2931
use Symfony\Component\DependencyInjection\ContainerBuilder;
3032
use Symfony\Component\DependencyInjection\ContainerInterface;
3133
use Symfony\Component\DependencyInjection\Definition;
@@ -1224,6 +1226,22 @@ public function testRemovesResourceCheckerConfigCacheFactoryArgumentOnlyIfNoDebu
12241226
$this->assertEmpty($container->getDefinition('config_cache_factory')->getArguments());
12251227
}
12261228

1229+
public function testLoggerAwareRegistration()
1230+
{
1231+
$container = $this->createContainerFromFile('full', array(), true, false);
1232+
$container->addCompilerPass(new ResolveInstanceofConditionalsPass());
1233+
$container->register('foo', LoggerAwareInterface::class)
1234+
->setAutoconfigured(true);
1235+
$container->compile();
1236+
1237+
$calls = $container->findDefinition('foo')->getMethodCalls();
1238+
1239+
$this->assertCount(1, $calls, 'Definition should contain 1 method call');
1240+
$this->assertSame('setLogger', $calls[0][0], 'Method name should be "setLogger"');
1241+
$this->assertInstanceOf(Reference::class, $calls[0][1][0]);
1242+
$this->assertSame('logger', (string) $calls[0][1][0], 'Argument should be a reference to "logger"');
1243+
}
1244+
12271245
protected function createContainer(array $data = array())
12281246
{
12291247
return new ContainerBuilder(new ParameterBag(array_merge(array(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.