Skip to content

Instantly share code, notes, and snippets.

@dmdeller
Created March 29, 2011 13:55
Show Gist options
  • Save dmdeller/892404 to your computer and use it in GitHub Desktop.
Save dmdeller/892404 to your computer and use it in GitHub Desktop.
<?php
namespace gadgetron\doctrine;
use Doctrine\ORM\Events;
class EventSubscriber implements \Doctrine\Common\EventSubscriber
{
public function getSubscribedEvents()
{
return array(Events::loadClassMetadata);
}
public function loadClassMetadata(\Doctrine\ORM\Event\LoadClassMetadataEventArgs $eventArgs)
{
$metadata = $eventArgs->getClassMetadata();
// if no custom repository is specified in annotations, use project base repository
if (empty($metadata->customRepositoryClassName))
{
$metadata->customRepositoryClassName = 'gadgetron\doctrine\EntityRepository';
}
}
}
<?php
// ...
// Create EventManager
$eventManager = new EventManager();
$eventManager->addEventSubscriber(new \gadgetron\doctrine\EventSubscriber());
// Create EntityManager
$entityManager = EntityManager::create($connectionOptions, $config, $eventManager);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment