class LoggerAwarePass

Same name in other branches
  1. 10 core/lib/Drupal/Core/DependencyInjection/Compiler/LoggerAwarePass.php \Drupal\Core\DependencyInjection\Compiler\LoggerAwarePass

Sets the logger on all services that implement LoggerAwareInterface.

Hierarchy

  • class \Drupal\Core\DependencyInjection\Compiler\LoggerAwarePass implements \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface

Expanded class hierarchy of LoggerAwarePass

1 file declares its use of LoggerAwarePass
CoreServiceProvider.php in core/lib/Drupal/Core/CoreServiceProvider.php

File

core/lib/Drupal/Core/DependencyInjection/Compiler/LoggerAwarePass.php, line 13

Namespace

Drupal\Core\DependencyInjection\Compiler
View source
class LoggerAwarePass implements CompilerPassInterface {
    
    /**
     * {@inheritdoc}
     */
    public function process(ContainerBuilder $container) : void {
        $interface = LoggerAwareInterface::class;
        foreach ($container->findTaggedServiceIds('logger_aware') as $id => $attributes) {
            $definition = $container->getDefinition($id);
            // Skip services that are already calling setLogger().
            if ($definition->hasMethodCall('setLogger')) {
                continue;
            }
            if (!is_subclass_of($definition->getClass(), $interface)) {
                throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
            }
            $providerTag = $definition->getTag('_provider');
            $loggerId = 'logger.channel.' . $providerTag[0]['provider'];
            if ($container->has($loggerId)) {
                $definition->addMethodCall('setLogger', [
                    new Reference($loggerId),
                ]);
            }
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
LoggerAwarePass::process public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.