Skip to content

[DI] [FrameworkBundle] Add LoggerAwareInterface to auto configuration #28176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CHANGELOG
* Allowed configuring PDO-based cache pools via a new `cache.adapter.pdo` abstract service
* Deprecated auto-injection of the container in AbstractController instances, register them as service subscribers instead
* Deprecated processing of services tagged `security.expression_language_provider` in favor of a new `AddExpressionLanguageProvidersPass` in SecurityBundle.
* Enabled autoconfiguration for `Psr\Log\LoggerAwareInterface`

4.1.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\Reader;
use Psr\Log\LoggerAwareInterface;
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
use Symfony\Bridge\Monolog\Processor\ProcessorInterface;
use Symfony\Bridge\Twig\Extension\CsrfExtension;
Expand Down Expand Up @@ -360,6 +361,8 @@ public function load(array $configs, ContainerBuilder $container)
->addTag('messenger.message_handler');
$container->registerForAutoconfiguration(TransportFactoryInterface::class)
->addTag('messenger.transport_factory');
$container->registerForAutoconfiguration(LoggerAwareInterface::class)
->addMethodCall('setLogger', array(new Reference('logger')));

if (!$container->getParameter('kernel.debug')) {
// remove tagged iterator argument for resource checkers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;

use Doctrine\Common\Annotations\Annotation;
use Psr\Log\LoggerAwareInterface;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
Expand All @@ -26,6 +27,7 @@
use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
Expand Down Expand Up @@ -1224,6 +1226,22 @@ public function testRemovesResourceCheckerConfigCacheFactoryArgumentOnlyIfNoDebu
$this->assertEmpty($container->getDefinition('config_cache_factory')->getArguments());
}

public function testLoggerAwareRegistration()
{
$container = $this->createContainerFromFile('full', array(), true, false);
$container->addCompilerPass(new ResolveInstanceofConditionalsPass());
$container->register('foo', LoggerAwareInterface::class)
->setAutoconfigured(true);
$container->compile();

$calls = $container->findDefinition('foo')->getMethodCalls();

$this->assertCount(1, $calls, 'Definition should contain 1 method call');
$this->assertSame('setLogger', $calls[0][0], 'Method name should be "setLogger"');
$this->assertInstanceOf(Reference::class, $calls[0][1][0]);
$this->assertSame('logger', (string) $calls[0][1][0], 'Argument should be a reference to "logger"');
}

protected function createContainer(array $data = array())
{
return new ContainerBuilder(new ParameterBag(array_merge(array(
Expand Down