Workaround to the circular referencing problem (unless you can solve it using DI) @see stof's bundle
<?php
namespace ACME\CoreBundle\Listener;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class ReferencesListener
*
* @package ACME\CoreBundle\Listener
*/
class ReferencesListener extends \Gedmo\References\ReferencesListener
{
/**
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
private $container;
/**
* @var array
*/
protected $managers
= [
'document' => 'doctrine.odm.mongodb.document_manager',
'entity' => 'doctrine.orm.default_entity_manager'
];
/**
* @param ContainerInterface $container
* @param array $managers
*/
public function __construct(ContainerInterface $container, array $managers = array())
{
$this->container = $container;
parent::__construct($managers);
}
/**
* @param $type
*
* @return object
*/
public function getManager($type)
{
return $this->container->get($this->managers[$type]);
}
}
Listener defination
acme.listener.reference:
class: ACME\CoreBundle\Listener\ReferencesListener
arguments: ["@service_container"]
tags:
- { name: doctrine.event_subscriber, connection: default }