‪TYPO3CMS  10.4
LoggerAwarePass.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
21 use Symfony\Component\DependencyInjection\ContainerBuilder;
22 use Symfony\Component\DependencyInjection\Definition;
23 use Symfony\Component\DependencyInjection\Reference;
26 
30 final class ‪LoggerAwarePass implements CompilerPassInterface
31 {
35  private ‪$tagName;
36 
40  public function ‪__construct(string ‪$tagName)
41  {
42  $this->tagName = ‪$tagName;
43  }
44 
48  public function ‪process(ContainerBuilder $container)
49  {
50  foreach ($container->findTaggedServiceIds($this->tagName) as $id => $tags) {
51  $definition = $container->findDefinition($id);
52  if (!$definition->isAutowired() || $definition->isAbstract()) {
53  continue;
54  }
55 
56  $logger = new Definition(Logger::class);
57  $logger->setFactory([new Reference(LogManager::class), 'getLogger']);
58  $logger->setArguments([$id]);
59  $logger->setShared(false);
60 
61  $definition->addMethodCall('setLogger', [$logger]);
62  }
63  }
64 }
‪TYPO3\CMS\Core\DependencyInjection\LoggerAwarePass\process
‪process(ContainerBuilder $container)
Definition: LoggerAwarePass.php:47
‪TYPO3\CMS\Core\DependencyInjection
Definition: AutowireInjectMethodsPass.php:18
‪TYPO3\CMS\Core\DependencyInjection\LoggerAwarePass\$tagName
‪string $tagName
Definition: LoggerAwarePass.php:34
‪TYPO3\CMS\Core\DependencyInjection\LoggerAwarePass\__construct
‪__construct(string $tagName)
Definition: LoggerAwarePass.php:39
‪TYPO3\CMS\Core\DependencyInjection\LoggerAwarePass
Definition: LoggerAwarePass.php:31
‪TYPO3\CMS\Core\Log\LogManager
Definition: LogManager.php:30
‪TYPO3\CMS\Core\Log\Logger
Definition: Logger.php:27