Description
Symfony version(s) affected: 4.1.4
Description
After upgrading to v4.1.4 the following error shown when container tries to build.
RuntimeException Cannot dump definitions which have method calls.
Tace
RuntimeException Cannot dump definitions which have method calls. [Symfony\Component\DependencyInjection\Exception\RuntimeException] Cannot dump definitions which have method calls.Exception trace:
Symfony\Component\DependencyInjection\Dumper\PhpDumper->dumpValue() at /var/www/html/vendor/symfony/dependency-injection/Dumper/PhpDumper.php:614
Symfony\Component\DependencyInjection\Dumper\PhpDumper->addServiceMethodCalls() at /var/www/html/vendor/symfony/dependency-injection/Dumper/PhpDumper.php:516
Symfony\Component\DependencyInjection\Dumper\PhpDumper->addServiceInlinedDefinitions() at /var/www/html/vendor/symfony/dependency-injection/Dumper/PhpDumper.php:792
Symfony\Component\DependencyInjection\Dumper\PhpDumper->addService() at /var/www/html/vendor/symfony/dependency-injection/Dumper/PhpDumper.php:827
Symfony\Component\DependencyInjection\Dumper\PhpDumper->addServices() at /var/www/html/vendor/symfony/dependency-injection/Dumper/PhpDumper.php:194
Symfony\Component\DependencyInjection\Dumper\PhpDumper->dump() at /var/www/html/vendor/symfony/http-kernel/Kernel.php:704
Symfony\Component\HttpKernel\Kernel->dumpContainer() at /var/www/html/vendor/symfony/http-kernel/Kernel.php:541
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /var/www/html/vendor/symfony/http-kernel/Kernel.php:123
Symfony\Component\HttpKernel\Kernel->boot() at /var/www/html/vendor/symfony/framework-bundle/Console/Application.php:65
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/html/vendor/symfony/console/Application.php:145
Symfony\Component\Console\Application->run() at /var/www/html/bin/console:39
possibly BC break
possibly caused by: #28060
(or maybe i missed something and used it wrong)
How to reproduce
I have a monolog handler that requires EntityManagerInterface and a doctrine EventSubscriber that needs the monolog logger with the handler. It works fine when I downgrade to symfony/dependency-injection to v4.1.3
Files that requre to reproduce:
src/Monolog/DoctrineDBHandler.php
namespace App\Monolog;
use Doctrine\ORM\EntityManagerInterface;
use Monolog\Handler\AbstractProcessingHandler;
class DoctrineDBHandler extends AbstractProcessingHandler
{
private $entityManager;
public function __construct(EntityManagerInterface $em)
{
parent::__construct();
$this->entityManager = $em;
}
protected function write(array $record): void
{
// write log to db
}
}
src/EventSubscriber/DoctrineLogSubscriber.php
namespace App\EventSubscriber;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Monolog\Logger;
class DoctrineLogSubscriber implements EventSubscriber
{
private $logger;
public function __construct(Logger $logger)
{
$this->logger = $logger;
}
public function getSubscribedEvents(): array
{
return ['postPersist'];
}
public function postPersist(LifecycleEventArgs $args): void
{
$this->logger->addInfo('create');
}
}
config/services.yaml
parameters:
locale: 'en'
services:
_defaults:
autowire: true
autoconfigure: true
public: false
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
App\DoctrineLogSubscriber:
arguments: ['@monolog.logger.demo']
tags:
- { name: doctrine.event_subscriber }
config/packages/dev/monolog.yaml
...
monolog:
channels: ['demo']
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ["!event"]
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine", "!console"]
demo:
channels: ['demo']
level: INFO
type: service
id: App\Monolog\DoctrineDBHandler