public function __construct(array $dbConfig, array $options = array()) { extract($options); $entityClassLoader = new ClassLoader("Entities", $entityPath); $entityClassLoader->register(); $proxyPath = isset($proxyPath) ? $proxyPath : $entityPath; $proxyClassLoader = new ClassLoader("Proxies", $proxyPath); $proxyClassLoader->register(); $config = new Configuration(); if ($isDevMode || $isArrayCache) { $cache = new ArrayCache(); } else { $cache = new ApcCache(); } $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $config->setProxyDir($proxyPath); $config->setProxyNamespace($namespaces["proxy"]); if (isset($isDevMode) && $isDevMode) { $config->setAutogenerateProxyClasses(true); } if (isset($driverClass) && class_exists($driverClass)) { $annotationDriver = new $driverClass($entity_driver); } else { $annotationDriver = new AnnotationDriver(new AnnotationReader(), array($entityPath)); AnnotationRegistry::registerLoader('class_exists'); } $config->setMetadataDriverImpl($annotationDriver); $this->setEntityManager($dbConfig, $config); }
public function register(Application $app) { $app['doctrine_orm.configuration'] = $app->share(function ($app) { $configuration = new Configuration(); if (isset($app['doctrine_orm.metadata_cache'])) { $configuration->setMetadataCacheImpl($app['doctrine_orm.metadata_cache']); } else { $configuration->setMetadataCacheImpl(new ArrayCache()); } $driverImpl = $configuration->newDefaultAnnotationDriver($app['doctrine_orm.entities_path']); $configuration->setMetadataDriverImpl($driverImpl); if (isset($app['doctrine_orm.query_cache'])) { $configuration->setQueryCacheImpl($app['doctrine_orm.query_cache']); } else { $configuration->setQueryCacheImpl(new ArrayCache()); } if (isset($app['doctrine_orm.result_cache'])) { $configuration->setResultCacheImpl($app['doctrine_orm.result_cache']); } $configuration->setProxyDir($app['doctrine_orm.proxies_path']); $configuration->setProxyNamespace($app['doctrine_orm.proxies_namespace']); $configuration->setAutogenerateProxyClasses(false); if (isset($app['doctrine_orm.autogenerate_proxy_classes'])) { $configuration->setAutogenerateProxyClasses($app['doctrine_orm.autogenerate_proxy_classes']); } else { $configuration->setAutogenerateProxyClasses(true); } return $configuration; }); $app['doctrine_orm.connection'] = $app->share(function ($app) { return DriverManager::getConnection($app['doctrine_orm.connection_parameters'], $app['doctrine_orm.configuration'], new EventManager()); }); $app['doctrine_orm.em'] = $app->share(function ($app) { return EntityManager::create($app['doctrine_orm.connection'], $app['doctrine_orm.configuration'], $app['doctrine_orm.connection']->getEventManager()); }); }