DebugHandlerPass.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\MonologBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Reference;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  14. use Symfony\Component\DependencyInjection\Definition;
  15. use Monolog\Logger;
  16. /**
  17. * Adds the DebugHandler when the profiler is enabled and kernel.debug is true.
  18. *
  19. * @author Christophe Coevoet <stof@notk.org>
  20. * @author Jordi Boggiano <j.boggiano@seld.be>
  21. *
  22. * @deprecated since version 2.12, to be removed in 4.0. Use AddDebugLogProcessorPass in FrameworkBundle instead.
  23. */
  24. class DebugHandlerPass implements CompilerPassInterface
  25. {
  26. private $channelPass;
  27. public function __construct(LoggerChannelPass $channelPass)
  28. {
  29. @trigger_error('The '.__CLASS__.' class is deprecated since version 2.12 and will be removed in 4.0. Use AddDebugLogProcessorPass in FrameworkBundle instead.', E_USER_DEPRECATED);
  30. $this->channelPass = $channelPass;
  31. }
  32. public function process(ContainerBuilder $container)
  33. {
  34. if (!$container->hasDefinition('profiler')) {
  35. return;
  36. }
  37. if (!$container->getParameter('kernel.debug')) {
  38. return;
  39. }
  40. $debugHandler = new Definition('Symfony\Bridge\Monolog\Handler\DebugHandler', [Logger::DEBUG, true]);
  41. $container->setDefinition('monolog.handler.debug', $debugHandler);
  42. foreach ($this->channelPass->getChannels() as $channel) {
  43. $container
  44. ->getDefinition($channel === 'app' ? 'monolog.logger' : 'monolog.logger.'.$channel)
  45. ->addMethodCall('pushHandler', [new Reference('monolog.handler.debug')]);
  46. }
  47. }
  48. }