/**
  * @param EventManager           $manager
  * @param EntityManagerInterface $em
  * @param Reader                 $reader
  */
 public function addSubscribers(EventManager $manager, EntityManagerInterface $em, Reader $reader)
 {
     $subscriber = new BlameableListener();
     $subscriber->setAnnotationReader($reader);
     if ($this->guard->check()) {
         $subscriber->setUserValue($this->guard->user());
     }
     $manager->addEventSubscriber($subscriber);
 }
 /**
  *
  * @return EntityManager
  */
 public function getEntityManager()
 {
     $cache = new DoctrineCache\ArrayCache();
     $annotationReader = new AnnotationReader();
     $cachedAnnotationReader = new CachedReader($annotationReader, $cache);
     // create a driver chain for metadata reading
     $driverChain = new MappingDriverChain();
     // load superclass metadata mapping only, into driver chain
     // also registers Gedmo annotations.NOTE: you can personalize it
     Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader);
     // now we want to register our application entities,
     // for that we need another metadata driver used for Entity namespace
     $annotationDriver = new AnnotationDriver($cachedAnnotationReader, $this->paths);
     $driverChain->addDriver($annotationDriver, $this->namespace);
     // general ORM configuration
     $isDevMode = $this->env != "production";
     $config = DoctrineSetup::createAnnotationMetadataConfiguration($this->paths, $isDevMode);
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     $config->setMetadataDriverImpl($driverChain);
     $config->setProxyDir($this->proxy_path);
     $config->setProxyNamespace($this->namespace . '\\Proxy');
     $config->setAutoGenerateProxyClasses($isDevMode);
     // Third, create event manager and hook prefered extension listeners
     $evm = new EventManager();
     // gedmo extension listeners
     // sluggable
     $sluggableListener = new Gedmo\Sluggable\SluggableListener();
     // you should set the used annotation reader to listener, to avoid creating new one for mapping drivers
     $sluggableListener->setAnnotationReader($cachedAnnotationReader);
     $evm->addEventSubscriber($sluggableListener);
     // tree
     $treeListener = new Gedmo\Tree\TreeListener();
     $treeListener->setAnnotationReader($cachedAnnotationReader);
     $evm->addEventSubscriber($treeListener);
     // loggable, not used in example
     $loggableListener = new Gedmo\Loggable\LoggableListener();
     $loggableListener->setAnnotationReader($cachedAnnotationReader);
     $loggableListener->setUsername('unknown');
     $evm->addEventSubscriber($loggableListener);
     // timestampable
     $timestampableListener = new Gedmo\Timestampable\TimestampableListener();
     $timestampableListener->setAnnotationReader($cachedAnnotationReader);
     $evm->addEventSubscriber($timestampableListener);
     // blameable
     $blameableListener = new Gedmo\Blameable\BlameableListener();
     $blameableListener->setAnnotationReader($cachedAnnotationReader);
     $blameableListener->setUserValue('unknown');
     // determine from your environment
     $evm->addEventSubscriber($blameableListener);
     // translatable - buggy !!!
     /*
     $translatableListener = new Gedmo\Translatable\TranslatableListener();
     // current translation locale should be set from session or hook later into the listener
     // most important, before entity manager is flushed
     $translatableListener->setTranslatableLocale('en');
     $translatableListener->setDefaultLocale('en');
     $translatableListener->setAnnotationReader($cachedAnnotationReader);
     $evm->addEventSubscriber($translatableListener);
     */
     // sortable, not used in example
     $sortableListener = new Gedmo\Sortable\SortableListener();
     $sortableListener->setAnnotationReader($cachedAnnotationReader);
     $evm->addEventSubscriber($sortableListener);
     // mysql set names UTF-8 if required
     $evm->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit());
     // Finally, create entity manager
     return EntityManager::create($this->dbParams, $config, $evm);
 }