Hay varias formas de resolverlo, te dejo una, de todas formas ten en cuenta que no es lo ideal, deberias delegar esto en un service.
services.xml
Código XML:
Ver original<parameters>
<parameter key="app.repository.organization.class">App\CoreBundle\Entity\OrganizationRepository</parameter>
<parameter key="app.model.organization.class">App\CoreBundle\Entity\Organization</parameter>
</parameters>
<services>
<service id="app.manager.organization" alias="doctrine.orm.entity_manager" />
<service id="app.repository.organization" class="%app.repository.organization.class%">
<argument type="service" id="app.manager.organization" />
<argument type="service">
<service id="app.doctrine.orm.metadata.organization"
factory-service="app.manager.organization"
factory-method="getClassMetadata"
class="Doctrine\ORM\Mapping\ClassMetadata"
>
<argument>%app.model.organization.class%</argument>
</service>
</argument>
<argument type="service" id="event_dispatcher" />
</service>
</services>
Repository
Código PHP:
Ver originalnamespace App\CoreBundle\Entity;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping\ClassMetadata;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\Event;
class OrganizationRepository extends EntityRepository
{
protected $ed;
public function __construct($em, ClassMetadata $class, EventDispatcherInterface $ed)
{
parent::__construct($em, $class);
$this->ed = $ed;
}
public function foo()
{
$this->ed->dispatch('foo', new Event());
...
}
}
Obviamente luego debes obtener el repositorio del container de Symfony y no del manager de Doctrine ;)
Saludos.