symfony: [Doctrine] problem with events
SF 2.3.1 events doesn’t work, because appDevDebugProjectContainer has extra lines after return tag:
protected function getDoctrine_Dbal_DefaultConnectionService()
{
$a = new \Doctrine\DBAL\Logging\LoggerChain();
$a->addLogger(new \Symfony\Bridge\Doctrine\Logger\DbalLogger($this->get('monolog.logger.doctrine', ContainerInterface::NULL_ON_INVALID_REFERENCE), $this->get('debug.stopwatch', ContainerInterface::NULL_ON_INVALID_REFERENCE)));
$a->addLogger($this->get('doctrine.dbal.logger.profiling.default'));
$b = new \Doctrine\DBAL\Configuration();
$b->setSQLLogger($a);
$c = new \Symfony\Bridge\Doctrine\ContainerAwareEventManager($this);
return $this->services['doctrine.dbal.default_connection'] = $this->get('doctrine.dbal.connection_factory')->createConnection(array('dbname' => 'test', 'host' => '127.0.0.1', 'port' => NULL, 'user' => 'test', 'password' => 'test', 'charset' => 'UTF8', 'driver' => 'pdo_mysql', 'driverOptions' => array()), $b, $c, array());
$c->addEventSubscriber(new \FOS\UserBundle\Entity\UserListener($this));
$c->addEventListener(array(0 => 'prePersist'), $this->get('test_listener'));
}
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Comments: 26 (20 by maintainers)
Commits related to this issue
- [DependencyInjection] fixed a non-detected circular reference in PhpDumper (closes #8425) This circular reference cannot be detected by the compiler pass as we don't check for method arguments there.... — committed to fabpot/symfony by fabpot 11 years ago
- merged branch fabpot/circular-refs-php-dumper (PR #8999) This PR was merged into the 2.2 branch. Discussion ---------- [DependencyInjection] fixed a non-detected circular reference in PhpDumper (cl... — committed to symfony/symfony by fabpot 11 years ago
- Merge branch '2.2' into 2.3 * 2.2: [HttpKernel] added a check for private event listeners/subscribers [FrameworkBundle] fixed registration of the register listener pass [Form] Fixed regression ... — committed to symfony/symfony by fabpot 11 years ago
- Merge branch '2.3' * 2.3: [HttpKernel] added a check for private event listeners/subscribers [FrameworkBundle] fixed registration of the register listener pass [Form] Fixed regression causing i... — committed to symfony/symfony by fabpot 11 years ago
@Sirian This is a circular reference. This object graph requires to instantiate the entity manager before instantiating Foo, and to instantiate Foo before the TestListener. But the TestListener needs to be instantiating when building the doctrine EventManager required by the EntityManager. And here, you see the issue: where can we start instantiating ? nowhere.
@Sirian Why do you even want to inject the entity manager?
As you can see here, you can get the entity manager from LifecycleEventArgs. http://symfony.com/doc/current/cookbook/doctrine/event_listeners_subscribers.html#creating-the-listener-class
If I am trying to reproduce I am getting a circular reference error.