/**
  * Registers services on the given app.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  * @param Application $app
  */
 public function register(Application $app)
 {
     parent::register($app);
     $app->register(new \Silex\Provider\DoctrineServiceProvider(), ['db.options' => $app['config']['db.options']]);
     $app->register(new DoctrineOrmServiceProvider(), $app['config']['orm.options']);
     if (getenv('MIGRATION_COMMANDS')) {
         $app->register(new MigrationServiceProvider(), ['db.migrations.path' => $app['config']['migrations.directory']]);
     }
     $app['orm.em'] = $app->extend('orm.em', function (EntityManagerInterface $em) use($app) {
         if (file_exists(APP_PATH . '/vendor/apitude/apitude/src/Annotations/APIAnnotations.php')) {
             AnnotationRegistry::registerFile(APP_PATH . '/vendor/apitude/apitude/src/Annotations/APIAnnotations.php');
         }
         /** @var Configuration $config */
         $config = $em->getConfiguration();
         $config->setMetadataCacheImpl($app['cache']);
         $config->addCustomHydrationMode('simple', SimpleHydrator::class);
         /** @var MappingDriverChain $driver */
         $driver = $config->getMetadataDriverImpl();
         // gedmo initialization
         $reader = new AnnotationReader();
         $cache = new CachedReader($reader, $app['cache']);
         DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driver, $cache);
         return $em;
     });
 }
 /**
  * Get entity manager.
  *
  * @return EntityManagerInterface
  */
 protected function getEntityManager()
 {
     if (null === $this->entityManager) {
         $params = ['driver' => 'pdo_sqlite', 'memory' => true];
         $cache = new ArrayCache();
         /** @var AnnotationReader $reader */
         $reader = new CachedReader(new AnnotationReader(), $cache);
         $annotationDriver = new AnnotationDriver($reader, [__DIR__ . '/../../../src/ORM']);
         $driverChain = new MappingDriverChain();
         $driverChain->addDriver($annotationDriver, Commander::ENTITY_NAMESPACE);
         DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $reader);
         $config = new Configuration();
         $config->setAutoGenerateProxyClasses(true);
         $config->setProxyDir(sys_get_temp_dir());
         $config->setProxyNamespace(Commander::ENTITY_NAMESPACE);
         $config->setMetadataDriverImpl($driverChain);
         $config->setMetadataCacheImpl($cache);
         $config->setQueryCacheImpl($cache);
         $config->setResultCacheImpl($cache);
         $config->setHydrationCacheImpl($cache);
         $timestampableListener = new TimestampableListener();
         $timestampableListener->setAnnotationReader($annotationDriver->getReader());
         $eventManager = new EventManager();
         $eventManager->addEventSubscriber($timestampableListener);
         $entityManager = EntityManager::create($params, $config, $eventManager);
         $schemaTool = new SchemaTool($entityManager);
         $schemaTool->createSchema($entityManager->getMetadataFactory()->getAllMetadata());
         $this->entityManager = $entityManager;
     }
     return $this->entityManager;
 }
 /**
  * Boot the service provider
  *
  * @param ManagerRegistry $registry
  */
 public function boot(ManagerRegistry $registry)
 {
     foreach ($registry->getManagers() as $manager) {
         $chain = $manager->getConfiguration()->getMetadataDriverImpl();
         $reader = $chain->getReader();
         if ($this->app->make('config')->get('doctrine.gedmo.all_mappings', false)) {
             DoctrineExtensions::registerMappingIntoDriverChainORM($chain, $reader);
         } else {
             DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($chain, $reader);
         }
     }
 }
 /**
  * Get mapping driver.
  *
  * @return MappingDriver
  */
 public function getMappingDriver()
 {
     if (null === $this->mappingDriver) {
         /** @var AnnotationReader $reader */
         $reader = new CachedReader(new AnnotationReader(), $this->cache);
         $annotationDriver = new AnnotationDriver($reader, [__DIR__ . '/../ORM']);
         $driverChain = new MappingDriverChain();
         $driverChain->addDriver($annotationDriver, Commander::ENTITY_NAMESPACE);
         DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $reader);
         $this->mappingDriver = $driverChain;
     }
     return $this->mappingDriver;
 }
 /**
  * @param $datasourceName
  * @return mixed
  */
 public function getEntityManager($datasourceName = null)
 {
     if ($datasourceName === null) {
         $datasourceName = ConfigManager::get('datasources.default');
     } else {
         if (!is_string($datasourceName) || empty($datasourceName)) {
             throw new \InvalidArgumentException('Invalid datasource name "' . (string) $datasourceName . '"');
         }
     }
     if (!array_key_exists($datasourceName, self::$connections)) {
         $isDebug = ConfigManager::exists('datasources.debug') ? ConfigManager::get('datasources.debug') : false;
         $cacheName = ConfigManager::get('datasources.list.' . $datasourceName . '.cache');
         $cacheClass = '\\Doctrine\\Common\\Cache\\' . (!empty($cacheName) ? $cacheName : 'ArrayCache');
         $entityManagerConfig = Setup::createConfiguration($isDebug);
         //Load annotations stuff
         AnnotationRegistry::registerFile(VENDORS_DIR . 'doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
         $cache = new $cacheClass();
         $annotationReader = new AnnotationReader();
         $cachedAnnotationReader = new CachedReader($annotationReader, $cache, $isDebug);
         //Load event manager
         $this->eventManager = new EventManager();
         $listenersList = ConfigManager::get('datasources.listeners');
         if (!empty($listenersList)) {
             foreach ($listenersList as $listener) {
                 $l = new $listener();
                 $this->eventManager->addEventSubscriber($l);
             }
         }
         //Tables prefix
         if (ConfigManager::exists('datasources.list.' . $datasourceName . '.prefix')) {
             $tablePrefix = new DoctrineTablePrefixListener(ConfigManager::get('datasources.list.' . $datasourceName . '.prefix'));
             $this->eventManager->addEventListener(Events::loadClassMetadata, $tablePrefix);
         }
         //Load doctrine extensions listeners if any
         if (!empty($listenersList) && class_exists('\\Gedmo\\DoctrineExtensions')) {
             $driverChain = new MappingDriverChain();
             DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader);
         }
         $driver = new AnnotationDriver($cachedAnnotationReader, glob(APP_DIR . '*/entity'));
         $entityManagerConfig->setMetadataDriverImpl($driver);
         self::$entityManagers[$datasourceName] = EntityManager::create(ConfigManager::get('datasources.list.' . $datasourceName), $entityManagerConfig, $this->eventManager);
     }
     return self::$entityManagers[$datasourceName];
 }
示例#6
0
文件: Database.php 项目: fraym/core
 /**
  * @return $this
  */
 public function connect()
 {
     // Prevent to connect twice
     if ($this->entityManager) {
         return $this;
     }
     $applicationDir = $this->core->getApplicationDir();
     $this->createModuleDirCache();
     $cache = $this->cache->getCacheProvider();
     $config = new \Doctrine\ORM\Configuration();
     $config->setMetadataCacheImpl($cache);
     $config->addCustomStringFunction('MD5', '\\DoctrineExtensions\\Query\\Mysql\\Md5');
     $config->addCustomStringFunction('ACOS', '\\DoctrineExtensions\\Query\\Mysql\\Acos');
     $config->addCustomStringFunction('ASIN', '\\DoctrineExtensions\\Query\\Mysql\\Asin');
     $config->addCustomStringFunction('ATAN', '\\DoctrineExtensions\\Query\\Mysql\\Atan');
     $config->addCustomStringFunction('ATAN2', '\\DoctrineExtensions\\Query\\Mysql\\Atan2');
     $config->addCustomStringFunction('BINARY', '\\DoctrineExtensions\\Query\\Mysql\\Binary');
     $config->addCustomStringFunction('CHARLENGTH', '\\DoctrineExtensions\\Query\\Mysql\\CharLength');
     $config->addCustomStringFunction('CONCATWS', '\\DoctrineExtensions\\Query\\Mysql\\ConcatWs');
     $config->addCustomStringFunction('COS', '\\DoctrineExtensions\\Query\\Mysql\\Cos');
     $config->addCustomStringFunction('COT', '\\DoctrineExtensions\\Query\\Mysql\\COT');
     $config->addCustomStringFunction('COUNTIF', '\\DoctrineExtensions\\Query\\Mysql\\CountIf');
     $config->addCustomStringFunction('CRC32', '\\DoctrineExtensions\\Query\\Mysql\\Crc32');
     $config->addCustomStringFunction('DATE', '\\DoctrineExtensions\\Query\\Mysql\\Date');
     $config->addCustomStringFunction('DATEADD', '\\DoctrineExtensions\\Query\\Mysql\\DateAdd');
     $config->addCustomStringFunction('DATEDIFF', '\\DoctrineExtensions\\Query\\Mysql\\DateFormat');
     $config->addCustomStringFunction('DAY', '\\DoctrineExtensions\\Query\\Mysql\\Day');
     $config->addCustomStringFunction('DEGREES', '\\DoctrineExtensions\\Query\\Mysql\\Degrees');
     $config->addCustomStringFunction('FIELD', '\\DoctrineExtensions\\Query\\Mysql\\Field');
     $config->addCustomStringFunction('FINDINSET', '\\DoctrineExtensions\\Query\\Mysql\\FindInSet');
     $config->addCustomStringFunction('GROUPCONCAT', '\\DoctrineExtensions\\Query\\Mysql\\GroupConcat');
     $config->addCustomStringFunction('HOUR', '\\DoctrineExtensions\\Query\\Mysql\\Hour');
     $config->addCustomStringFunction('IFELSE', '\\DoctrineExtensions\\Query\\Mysql\\IfElse');
     $config->addCustomStringFunction('IFNULL', '\\DoctrineExtensions\\Query\\Mysql\\IfNUll');
     $config->addCustomStringFunction('MATCHAGAINST', '\\DoctrineExtensions\\Query\\Mysql\\MatchAgainst');
     $config->addCustomStringFunction('MONTH', '\\DoctrineExtensions\\Query\\Mysql\\Month');
     $config->addCustomStringFunction('NULLIF', '\\DoctrineExtensions\\Query\\Mysql\\NullIf');
     $config->addCustomStringFunction('PI', '\\DoctrineExtensions\\Query\\Mysql\\Pi');
     $config->addCustomStringFunction('RADIANS', '\\DoctrineExtensions\\Query\\Mysql\\Radians');
     $config->addCustomStringFunction('RAND', '\\DoctrineExtensions\\Query\\Mysql\\Rand');
     $config->addCustomStringFunction('REGEXP', '\\DoctrineExtensions\\Query\\Mysql\\Regexp');
     $config->addCustomStringFunction('ROUND', '\\DoctrineExtensions\\Query\\Mysql\\Round');
     $config->addCustomStringFunction('SHA1', '\\DoctrineExtensions\\Query\\Mysql\\Sha1');
     $config->addCustomStringFunction('SHA2', '\\DoctrineExtensions\\Query\\Mysql\\Sha2');
     $config->addCustomStringFunction('SIN', '\\DoctrineExtensions\\Query\\Mysql\\Sin');
     $config->addCustomStringFunction('STRTODATE', '\\DoctrineExtensions\\Query\\Mysql\\StrToDate');
     $config->addCustomStringFunction('TAN', '\\DoctrineExtensions\\Query\\Mysql\\Tan');
     $config->addCustomStringFunction('TIMESTAMPDIFF', '\\DoctrineExtensions\\Query\\Mysql\\TimestampDiff');
     $config->addCustomStringFunction('WEEK', '\\DoctrineExtensions\\Query\\Mysql\\Week');
     $config->addCustomStringFunction('YEAR', '\\DoctrineExtensions\\Query\\Mysql\\Year');
     if (!defined('ENV') || ENV === \Fraym\Core::ENV_DEVELOPMENT) {
         $config->setAutoGenerateProxyClasses(true);
     }
     $modelDirs = $this->getModuleDirCache();
     \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(function ($class) {
         return class_exists($class, true);
     });
     $annotationReader = new \Doctrine\Common\Annotations\AnnotationReader();
     $this->cachedAnnotationReader = new \Doctrine\Common\Annotations\CachedReader($annotationReader, $cache);
     $this->annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($this->cachedAnnotationReader, $modelDirs);
     /**
      * Ignore PHP-DI Annotation
      */
     $annotationReader->addGlobalIgnoredName('Injectable');
     $annotationReader->addGlobalIgnoredName('Inject');
     $config->setMetadataDriverImpl($this->annotationDriver);
     $config->setQueryCacheImpl($cache);
     $config->setResultCacheImpl($cache);
     $config->setProxyDir($applicationDir . DIRECTORY_SEPARATOR . CACHE_DOCTRINE_PROXY_PATH);
     $config->setProxyNamespace('Proxies');
     $this->fetchMode = \PDO::FETCH_OBJ;
     $tablePrefix = new TablePrefix(DB_TABLE_PREFIX);
     $this->eventManager = new \Doctrine\Common\EventManager();
     $this->eventManager->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix);
     $this->entityManager = \Doctrine\ORM\EntityManager::create($this->connectionOptions, $config, $this->eventManager);
     $this->pdo = $this->entityManager->getConnection();
     $this->pdo->getDatabasePlatform()->registerDoctrineTypeMapping('set', 'string');
     $driverChain = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();
     \Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $this->cachedAnnotationReader);
     $this->eventManager->addEventListener([\Doctrine\ORM\Events::preRemove, \Doctrine\ORM\Events::postRemove, \Doctrine\ORM\Events::prePersist, \Doctrine\ORM\Events::postPersist, \Doctrine\ORM\Events::preUpdate, \Doctrine\ORM\Events::postUpdate, \Doctrine\ORM\Events::postLoad, \Doctrine\ORM\Events::onFlush], $this->eventListener);
     return $this;
 }
示例#7
0
 public function register(Application $app)
 {
     $app['EM.sql-logger.file'] = $app->share(function (Application $app) {
         return $app['log.path'] . '/doctrine-log.log';
     });
     $app['EM.sql-logger.max-files'] = 5;
     $app['EM.sql-logger'] = $app->share(function (Application $app) {
         $logger = new $app['monolog.logger.class']('doctrine-logger');
         $logger->pushHandler(new RotatingFileHandler($app['EM.sql-logger.file'], $app['EM.sql-logger.max-files']));
         return new MonologSQLLogger($logger, 'yaml');
     });
     $app['EM.driver'] = $app->share(function (Application $app) {
         AnnotationRegistry::registerFile($app['root.path'] . '/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
         $annotationReader = new AnnotationReader();
         $fileCacheReader = new FileCacheReader($annotationReader, $app['cache.path'] . '/doctrine', $app['debug']);
         $driverChain = new MappingDriverChain();
         DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $fileCacheReader);
         $annotationDriver = new AnnotationDriver($annotationReader, [$app['root.path'] . '/lib/Alchemy/Phrasea/Model/Entities']);
         $driverChain->addDriver($annotationDriver, 'Alchemy\\Phrasea\\Model\\Entities');
         return $driverChain;
     });
     $app['EM.config'] = $app->share(function (Application $app) {
         $config = new ORMConfiguration();
         if ($app->getEnvironment() === PhraseaApplication::ENV_DEV) {
             $config->setSQLLogger($app['EM.sql-logger']);
         }
         $config->setMetadataCacheImpl($app['phraseanet.cache-service']->factory('ORMmetadata', $app['EM.opcode-cache-type'], $app['EM.opcode-cache-options']));
         $config->setQueryCacheImpl($app['phraseanet.cache-service']->factory('ORMquery', $app['EM.opcode-cache-type'], $app['EM.opcode-cache-options']));
         $config->setResultCacheImpl($app['phraseanet.cache-service']->factory('ORMresult', $app['EM.cache-type'], $app['EM.cache-options']));
         $config->setAutoGenerateProxyClasses($app['debug']);
         $config->setMetadataDriverImpl($app['EM.driver']);
         $config->setProxyDir($app['root.path'] . '/resources/proxies');
         $config->setProxyNamespace('Alchemy\\Phrasea\\Model\\Proxies');
         $config->setAutoGenerateProxyClasses($app['debug']);
         $config->addEntityNamespace('Phraseanet', 'Alchemy\\Phrasea\\Model\\Entities');
         return $config;
     });
     $app['EM.opcode-cache-type'] = $app->share(function (Application $app) {
         if ($app['configuration.store']->isSetup()) {
             return $app['conf']->get(['main', 'opcodecache', 'type']);
         }
         return 'ArrayCache';
     });
     $app['EM.opcode-cache-options'] = $app->share(function (Application $app) {
         if ($app['configuration.store']->isSetup()) {
             return $app['conf']->get(['main', 'opcodecache', 'options']);
         }
         return [];
     });
     $app['EM.cache-type'] = $app->share(function (Application $app) {
         if ($app['configuration.store']->isSetup()) {
             return $app['conf']->get(['main', 'cache', 'type']);
         }
         return 'ArrayCache';
     });
     $app['EM.cache-options'] = $app->share(function (Application $app) {
         if ($app['configuration.store']->isSetup()) {
             return $app['conf']->get(['main', 'cache', 'options']);
         }
         return [];
     });
     $app['EM.events-manager'] = $app->share(function (Application $app) {
         $evm = new EventManager();
         $evm->addEventSubscriber(new TimestampableListener());
         return $evm;
     });
     $app['EM.dbal-conf'] = $app->share(function (Application $app) {
         if ('test' === $app->getEnvironment()) {
             return $app['conf']->get(['main', 'database-test']);
         }
         return $app['conf']->get(['main', 'database']);
     });
     $app['dbal.provider'] = $app->share(function (Application $app) {
         return new ConnectionProvider($app['EM.config'], $app['EM.events-manager'], isset($app['task-manager.logger']) ? $app['task-manager.logger'] : $app['monolog']);
     });
     $app['EM'] = $app->share(function (Application $app) {
         try {
             $em = EntityManager::create($app['EM.dbal-conf'], $app['EM.config'], $app['EM.events-manager']);
         } catch (\Exception $e) {
             throw new RuntimeException("Unable to create database connection", $e->getCode(), $e);
         }
         $platform = $em->getConnection()->getDatabasePlatform();
         $types = ['blob' => 'Alchemy\\Phrasea\\Model\\Types\\Blob', 'enum' => 'Alchemy\\Phrasea\\Model\\Types\\Blob', 'longblob' => 'Alchemy\\Phrasea\\Model\\Types\\LongBlob', 'varbinary' => 'Alchemy\\Phrasea\\Model\\Types\\VarBinary', 'binary' => 'Alchemy\\Phrasea\\Model\\Types\\Binary', 'binary_string' => 'Alchemy\\Phrasea\\Model\\Types\\BinaryString'];
         foreach ($types as $type => $class) {
             if (!Type::hasType($type)) {
                 Type::addType($type, $class);
             }
             $platform->registerDoctrineTypeMapping($type, $type);
         }
         return $em;
     });
     $app['EM.native-query'] = $app->share(function ($app) {
         return new NativeQueryProvider($app['EM']);
     });
 }
示例#8
0
 /**
  * Todo: Should be removed once GedmoExtension in the laravel-doctrine/extensions repo is tested to work
  * @param bool $all
  */
 public function enableGedmoExtensions($all = true)
 {
     if ($all) {
         DoctrineExtensions::registerMappingIntoDriverChainORM($this->driverChain->getChain(), $this->driverChain->getReader());
     } else {
         DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($this->driverChain->getChain(), $this->driverChain->getReader());
     }
 }
示例#9
0
 /**
  * @inheritdoc
  */
 protected static function _init_metadata($config, $connection_settings)
 {
     $type = \Arr::get($connection_settings, 'metadata_driver', 'annotation');
     if (!array_key_exists($type, static::$metadata_drivers)) {
         throw new DoctrineException('Invalid Doctrine2 metadata driver: ' . $type);
     }
     if ($type == 'annotation') {
         // Register the doctrine annotations
         AnnotationRegistry::registerFile(realpath(VENDORPATH) . '/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
         // Symfony Validator annotations
         AnnotationRegistry::registerAutoloadNamespace('Symfony\\Component\\Validator\\Constraints', array(realpath(VENDORPATH) . '/symfony/validator', PKGPATH . 'cmf/classes'));
         // Create cached annotation reader
         $cachedAnnotationReader = new CachedReader(new AnnotationReader(), $config->getMetadataCacheImpl());
         // Create a driver chain for metadata reading
         $driverChain = new MappingDriverChain();
         // Initialise Gedmo with the driver chain and reader
         DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader);
         // Create the annotation driver
         $annotationDriver = new AnnotationDriver($cachedAnnotationReader, \Arr::get($connection_settings, 'metadata_path', array()));
         // Add the driver for the configured namespaces
         $namespaces = array_unique(\Arr::get($connection_settings, 'entity_namespaces', array()));
         foreach ($namespaces as $namespace) {
             $driverChain->addDriver($annotationDriver, $namespace);
         }
         // And set it as the default driver for good measure
         $driverChain->setDefaultDriver($annotationDriver);
         return $driverChain;
     }
     $class = '\\Doctrine\\ORM\\Mapping\\Driver\\' . static::$metadata_drivers[$type];
     return new $class($connection_settings['metadata_path']);
 }
 /**
  * Enable Gedmo Doctrine Extensions
  *
  * @param array $namespaces
  * @param bool  $all
  */
 public function bootGedmoExtensions($namespaces = ['App'], $all = true)
 {
     if ($all) {
         DoctrineExtensions::registerMappingIntoDriverChainORM($this->chain, $this->reader);
     } else {
         DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($this->chain, $this->reader);
     }
     $driver = $this->metadata->getMetadataDriverImpl();
     foreach ($namespaces as $namespace) {
         $this->chain->addDriver($driver, $namespace);
     }
     $this->metadata->setMetadataDriverImpl($this->chain);
     $this->dispatcher->fire('doctrine.driver-chain::booted', [$driver, $this->chain]);
 }
 /**
  *
  * @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);
 }
示例#12
0
 protected function createDriver()
 {
     $this->driverChain = new \Doctrine\ORM\Mapping\Driver\DriverChain();
     \Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($this->driverChain, $this->cachedAnnotationReader);
     $entityDir = $this->config['general.namespace'] . '/Model/Entity';
     $entityPath = $this->config['general.appDir'] . 'src/' . $entityDir;
     $this->annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($this->cachedAnnotationReader, array($entityPath));
     $this->driverChain->addDriver($this->annotationDriver, $this->config['general.namespace'] . '\\Model\\Entity');
     $this->doctrineConfig->setMetadataDriverImpl($this->driverChain);
 }