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

Most upvoted comments

@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.