public function _initDoctrineEntityManager() { $this->bootstrap(array('classLoaders', 'doctrineCache')); $zendConfig = $this->getOptions(); // parameters required for connecting to the database. // the required attributes are driver, host, user, password and dbname $connectionParameters = $zendConfig['doctrine']['connectionParameters']; // now initialize the configuration object $configuration = new DoctrineConfiguration(); // the metadata cache is used to avoid parsing all mapping information every time // the framework is initialized. $configuration->setMetadataCacheImpl($this->getResource('doctrineCache')); // for performance reasons, it is also recommended to use a result cache $configuration->setResultCacheImpl($this->getResource('doctrineCache')); // if you set this option to true, Doctrine 2 will generate proxy classes for your entities // on the fly. This has of course impact on the performance and should therefore be disabled // in the production environment $configuration->setAutoGenerateProxyClasses($zendConfig['doctrine']['autoGenerateProxyClasses']); // the directory, where your proxy classes live $configuration->setProxyDir($zendConfig['doctrine']['proxyPath']); // the proxy classes' namespace $configuration->setProxyNamespace($zendConfig['doctrine']['proxyNamespace']); // the next option tells doctrine which description language we want to use for the mapping // information $driver = new YamlDriver($zendConfig['doctrine']['mappingPath']); $driver->setFileExtension('.yml'); $configuration->setMetadataDriverImpl($driver); // next, we create an event manager $eventManager = new DoctrineEventManager(); // now we have everything required to initialize the entity manager $entityManager = DoctrineEntityManager::create($connectionParameters, $configuration, $eventManager); Zend_Registry::set('em', $entityManager); return $entityManager; }
public function loadDoctrineConfiguration(Application $app) { $app['db.orm.config'] = $app->share(function () use($app) { $cache = $app['db.orm.cache']; $config = new ORMConfiguration(); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $chain = new MappingDriverChain(); foreach ((array) $app['db.orm.entities'] as $entity) { switch ($entity['type']) { case 'default': case 'annotation': $driver = $config->newDefaultAnnotationDriver((array) $entity['path'], false); $chain->addDriver($driver, $entity['namespace']); break; case 'yml': $driver = new YamlDriver((array) $entity['path']); $driver->setFileExtension('.yml'); $chain->addDriver($driver, $entity['namespace']); break; case 'xml': $driver = new XmlDriver((array) $entity['path'], $entity['namespace']); $driver->setFileExtension('.xml'); $chain->addDriver($driver, $entity['namespace']); break; default: throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $entity['type'])); break; } } $config->setMetadataDriverImpl($chain); $config->setProxyDir($app['db.orm.proxies_dir']); $config->setProxyNamespace($app['db.orm.proxies_namespace']); $config->setAutoGenerateProxyClasses($app['db.orm.auto_generate_proxies']); $config->addCustomHydrationMode('SimpleArrayHydrator', 'App\\Provider\\SimpleArrayHydrator'); // автолоад прокси $proxyDir = $app['db.orm.proxies_dir']; $proxyNamespace = $app['db.orm.proxies_namespace']; Autoloader::register($proxyDir, $proxyNamespace); return $config; }); }
public function loadDoctrineConfiguration(Application $app) { $self = $this; $app['db.orm.config'] = $app->share(function () use($app, $self) { $cache = $app['db.orm.cache']; $config = new ORMConfiguration(); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $chain = new DriverChain(); foreach ((array) $app['db.orm.entities'] as $entity) { switch ($entity['type']) { case 'default': case 'annotation': $driver = $config->newDefaultAnnotationDriver((array) $entity['path']); $chain->addDriver($driver, $entity['namespace']); break; case 'yml': $driver = new YamlDriver((array) $entity['path']); $driver->setFileExtension('.yml'); $chain->addDriver($driver, $entity['namespace']); break; case 'xml': $driver = new XmlDriver((array) $entity['path'], $entity['namespace']); $driver->setFileExtension('.xml'); $chain->addDriver($driver, $entity['namespace']); break; default: throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $entity['type'])); break; } $self->autoloader->registerNamespace($entity['namespace'], $entity['path']); } $config->setMetadataDriverImpl($chain); $config->setProxyDir($app['db.orm.proxies_dir']); $config->setProxyNamespace($app['db.orm.proxies_namespace']); $config->setAutoGenerateProxyClasses($app['db.orm.auto_generate_proxies']); return $config; }); }
public function loadDoctrineConfiguration(Application $app) { $app['doctrine.configuration'] = $app->share(function () use($app) { if (isset($app['doctrine.orm']) and true === $app['doctrine.orm']) { $config = new ORMConfiguration(); $cache = new ApcCache(); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $chain = new DriverChain(); foreach ((array) $app['doctrine.orm.entities'] as $entity) { switch ($entity['type']) { case 'annotation': $reader = new AnnotationReader(); $reader->setAnnotationNamespaceAlias('Doctrine\\ORM\\Mapping\\', 'orm'); $driver = new AnnotationDriver($reader, (array) $entity['path']); $chain->addDriver($driver, $entity['namespace']); break; case 'yml': $driver = new YamlDriver((array) $entity['path']); $driver->setFileExtension('.yml'); $chain->addDriver($driver, $entity['namespace']); break; case 'xml': $driver = new XmlDriver((array) $entity['path'], $entity['namespace']); $driver->setFileExtension('.xml'); $chain->addDriver($driver, $entity['namespace']); break; default: throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $type)); break; } } $config->setMetadataDriverImpl($chain); $config->setProxyDir($app['doctrine.orm.proxies_dir']); $config->setProxyNamespace($app['doctrine.orm.proxies_namespace']); $config->setAutoGenerateProxyClasses($app['doctrine.orm.auto_generate_proxies']); } else { $config = new DBALConfiguration(); } return $config; }); }
public function loadDoctrineConfiguration(Application $app) { $app['doctrine.configuration'] = $app->share(function () use($app) { if (isset($app['doctrine.orm']) and true === $app['doctrine.orm']) { // Check available cache drivers if (extension_loaded('apc')) { $cache = new ApcCache(); } else { if (extension_loaded('xcache')) { $cache = new XcacheCache(); } else { if (extension_loaded('memcache')) { $memcache = new \Memcache(); $memcache->connect('127.0.0.1'); $cache = new MemcacheCache(); $cache->setMemcache($memcache); } else { $cache = new ArrayCache(); } } } $cache->setNamespace("dc2_"); // to avoid collisions $config = new ORMConfiguration(); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $config->setResultCacheImpl($cache); $chain = new DriverChain(); foreach ((array) $app['doctrine.orm.entities'] as $entity) { switch ($entity['type']) { case 'annotation': $reader = new AnnotationReader(); $driver = new AnnotationDriver($reader, (array) $entity['path']); $chain->addDriver($driver, $entity['namespace']); break; case 'yml': $driver = new YamlDriver((array) $entity['path']); $driver->setFileExtension('.yml'); $chain->addDriver($driver, $entity['namespace']); break; case 'xml': $driver = new XmlDriver((array) $entity['path'], $entity['namespace']); $driver->setFileExtension('.xml'); $chain->addDriver($driver, $entity['namespace']); break; default: throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $entity['type'])); break; } } $config->setMetadataDriverImpl($chain); $config->setProxyDir($app['doctrine.orm.proxies_dir']); $config->setProxyNamespace($app['doctrine.orm.proxies_namespace']); $config->setAutoGenerateProxyClasses($app['doctrine.orm.auto_generate_proxies']); } else { $config = new DBALConfiguration(); } return $config; }); }