private function obterConfiguracao($dados) { $this->config = new Configuration(); // Definição do driver de mapeamento $metadata_driver = "Doctrine\\ORM\\Mapping\\Driver\\{$dados['metadata_driver']}"; if ($dados['metadata_driver'] == "AnnotationDriver") { $driver = $this->config->newDefaultAnnotationDriver(array(MODELO), true); } else { $driver = new $metadata_driver(CONFIG . DS . 'orm'); } if (!empty($dados['map_paths'])) { $driver->addPaths(preg_split('/, ?/', $dados['map_paths'])); } $this->config->setMetadataDriverImpl($driver); // Configurações de proxies $this->config->setProxyDir(RAIZ . DS . $dados['proxy_dir']); $this->config->setProxyNamespace($dados['proxy_namespace']); $this->config->setAutoGenerateProxyClasses($dados['auto_proxies']); // Definição da estratégia de caches de consultas e metadados $metadata_cache = "Doctrine\\Common\\Cache\\{$dados['metadata_cache']}"; $query_cache = "Doctrine\\Common\\Cache\\{$dados['query_cache']}"; $result_cache = "Doctrine\\Common\\Cache\\{$dados['query_cache']}"; $this->config->setMetadataCacheImpl(new $metadata_cache()); $this->config->setQueryCacheImpl(new $query_cache()); $this->config->setResultCacheImpl(new $result_cache()); // Ferramenta de log de consultas if (!empty($dados['sql_logger'])) { $sql_logger = "Doctrine\\DBAL\\Logging\\{$dados['sql_logger']}"; $logger = new $sql_logger(); $this->config->setSQLLogger($logger); } }
public function __construct() { // load database configuration from CodeIgniter require_once APPPATH . 'config/development/database.php'; // Set up class loading. You could use different autoloaders, provided by your favorite framework, // if you want to. require_once APPPATH . 'libraries/Doctrine/Common/ClassLoader.php'; $doctrineClassLoader = new ClassLoader('Doctrine', APPPATH . 'libraries'); $doctrineClassLoader->register(); $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, "/")); $entitiesClassLoader->register(); $proxiesClassLoader = new ClassLoader('Proxies', APPPATH . 'models/proxies'); $proxiesClassLoader->register(); // Set up caches $config = new Configuration(); $cache = new ArrayCache(); $config->setMetadataCacheImpl($cache); $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models/Entities')); $config->setMetadataDriverImpl($driverImpl); $config->setQueryCacheImpl($cache); $config->setQueryCacheImpl($cache); // Proxy configuration $config->setProxyDir(APPPATH . '/models/proxies'); $config->setProxyNamespace('Proxies'); // Set up logger $logger = new EchoSQLLogger(); $config->setSQLLogger($logger); $config->setAutoGenerateProxyClasses(TRUE); // Database connection information $connectionOptions = array('driver' => 'pdo_mysql', 'user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database']); // Create EntityManager $this->em = EntityManager::create($connectionOptions, $config); }
public function __construct() { // load database configuration from CodeIgniter require_once APPPATH . 'config/database.php'; // Set up class loading. You could use different autoloaders, provided by your favorite framework, // if you want to. //require_once APPPATH.'libraries/Doctrine/Common/ClassLoader.php'; // We use the Composer Autoloader instead - just set // $config['composer_autoload'] = TRUE; in application/config/config.php //require_once APPPATH.'vendor/autoload.php'; //A Doctrine Autoloader is needed to load the models $entitiesClassLoader = new ClassLoader('Entities', APPPATH . "models"); $entitiesClassLoader->register(); // Set up caches $config = new Configuration(); $cache = new ArrayCache(); $config->setMetadataCacheImpl($cache); $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models/Entities')); $config->setMetadataDriverImpl($driverImpl); $config->setQueryCacheImpl($cache); $config->setQueryCacheImpl($cache); // Proxy configuration $config->setProxyDir(APPPATH . '/models/proxies'); $config->setProxyNamespace('Proxies'); // Set up logger $logger = new EchoSQLLogger(); $config->setSQLLogger($logger); $config->setAutoGenerateProxyClasses(TRUE); // Database connection information $connectionOptions = array('driver' => 'pdo_mysql', 'user' => 'dev_pila', 'password' => 'damienludothomas', 'host' => 'localhost', 'dbname' => 'tradr'); // Create EntityManager $this->em = EntityManager::create($connectionOptions, $config); }
public static function createEntityManager($database) { $config = new Doctrine\ORM\Configuration(); // annotations $annotationDriver = $config->newDefaultAnnotationDriver(array(APP_DIR . '/Model', NEURON_DIR . '/Model')); $config->setMetadataDriverImpl($annotationDriver); // proxy $config->setProxyNamespace('Neuron\\Proxy'); $config->setProxyDir(TEMP_DIR); // cache $cache = Environment::isProduction() ? new NetteDoctrineCache() : new Doctrine\Common\Cache\ArrayCache(); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); // debugbar $config->setSQLLogger(Doctrine2Panel::getAndRegister()); // entity manager $em = Doctrine\ORM\EntityManager::create((array) $database, $config); $evm = $em->getEventManager(); $evm->addEventSubscriber(new Doctrine\DBAL\Event\Listeners\MysqlSessionInit("utf8", "utf8_czech_ci")); $evm->addEventSubscriber(new ValidationSubscriber()); $evm->addEventSubscriber(new CacheSubscriber()); $neonParser = new \Nette\NeonParser(); $aliases = $neonParser->parse(file_get_contents(APP_DIR . "/entityClassAliases.neon")); $evm->addEventSubscriber(new \Neuron\Model\Doctrine\EntityClassAliasesSubscriber($aliases)); return $em; }
public function __construct() { // load database configuration from CodeIgniter if (!file_exists($file_path = APPPATH . 'config/' . ENVIRONMENT . '/database.php') && !file_exists($file_path = APPPATH . 'config/database.php')) { throw new Exception('The configuration file database.php does not exist.'); } require $file_path; $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, "/")); $entitiesClassLoader->register(); $proxiesClassLoader = new ClassLoader('Proxies', APPPATH . 'models/Proxies'); $proxiesClassLoader->register(); // Set up caches $config = new Configuration(); $cache = new ArrayCache(); $config->setMetadataCacheImpl($cache); $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models/Entities')); $config->setMetadataDriverImpl($driverImpl); $config->setQueryCacheImpl($cache); $config->setQueryCacheImpl($cache); // Proxy configuration $config->setProxyDir(APPPATH . '/models/Proxies'); $config->setProxyNamespace('Proxies'); // Set up logger $logger = new EchoSQLLogger(); $config->setSQLLogger($logger); $config->setAutoGenerateProxyClasses(true); // Database connection information $connectionOptions = $this->convertDbConfig($db['default']); // Create EntityManager $this->em = EntityManager::create($connectionOptions, $config); }
protected static function setUpEntityManager() { $config = new Configuration(); $config->setSQLLogger(null); $config->setAutoGenerateProxyClasses(true); $config->setProxyDir(\sys_get_temp_dir()); $config->setProxyNamespace('Proxies'); $config->setMetadataDriverImpl(static::getMetadataDriverImpl()); $config->setQueryCacheImpl(new ArrayCache()); $config->setMetadataCacheImpl(new ArrayCache()); $dbPath = __DIR__ . '/../db.sqlite'; if (file_exists($dbPath)) { unlink($dbPath); } $connection = ['driver' => 'pdo_sqlite', 'path' => $dbPath]; // Event listeners $interfaces = DoctrineBundleMapping::getDefaultImplementations(); $evm = new EventManager(); // Resolve entity target subscriber $rtel = new ResolveTargetEntityListener(); foreach ($interfaces as $model => $implementation) { $rtel->addResolveTargetEntity($model, $implementation, []); } $evm->addEventSubscriber($rtel); // Load metadata subscriber $lm = new LoadMetadataSubscriber([], $interfaces); $evm->addEventSubscriber($lm); static::$em = EntityManager::create($connection, $config, $evm); }
/** * @param EntityManagerInterface $em * @param Configuration $configuration */ public function register(EntityManagerInterface $em, Configuration $configuration) { if ($this->debugbar->hasCollector('doctrine')) { $debugStack = $this->debugbar->getCollector('doctrine')->getDebugStack(); } else { $debugStack = new DebugStack(); $this->debugbar->addCollector(new DoctrineCollector($debugStack)); } $configuration->setSQLLogger($debugStack); }
/** * Initializes resource * * @return Doctrine\ORM\EntityManager */ public function init() { $options = $this->getOptions(); $config = new Configuration(); if (APPLICATION_ENV == 'production' && function_exists('apc_fetch')) { // @codeCoverageIgnoreStart #extension_loaded() memcache, xcache, redis $cache = new ApcCache(); } else { // @codeCoverageIgnoreEnd $cache = new ArrayCache(); } #$driverImpl = $config->newDefaultAnnotationDriver($options['modelDirectory']); // @todo Temporary(?) fix for using new AnnotationReader $reader = new AnnotationReader(); #$reader->setEnableParsePhpImports(true); $reader = new IndexedReader($reader); $reader = new CachedReader($reader, $cache); $driverImpl = new AnnotationDriver($reader, $options['modelDirectory']); class_exists('Doctrine\\ORM\\Mapping\\Driver\\DoctrineAnnotations'); // Beware cache slams: http://doctrine-orm.readthedocs.org/en/2.0.x/reference/caching.html#cache-slams $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $config->setResultCacheImpl($cache); $config->setProxyDir($options['proxyDirectory']); $config->setProxyNamespace($options['proxyNamespace']); $config->setAutoGenerateProxyClasses($options['autoGenerateProxyClasses']); $config->setMetadataDriverImpl($driverImpl); // @codeCoverageIgnoreStart if (null !== $options['logPath']) { $sqlLogger = new SqlLogger($options['logPath']); $config->setSQLLogger($sqlLogger); Zend_Registry::set('sqlLogger', $sqlLogger); } // @codeCoverageIgnoreEnd $entityManager = EntityManager::create($options['connection'], $config); Service::setEntityManager($entityManager); // Add BLOB data type mapping if (!Type::hasType('gzblob')) { Type::addType('gzblob', 'Rexmac\\Zyndax\\Doctrine\\DBAL\\Type\\GzBlob'); $entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('BLOB', 'gzblob'); } // Add IP data type mapping if (!Type::hasType('ip')) { Type::addType('ip', 'Rexmac\\Zyndax\\Doctrine\\DBAL\\Type\\Ip'); $entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('IP', 'ip'); } return $entityManager; }
/** * Sets up the doctrine configuration, caching, and entity manager * * @return EntityManager */ public function init() { $options = $this->getOptions(); if (!isset($options['connection'])) { throw new ConfigException('No doctrine connection settings set'); } $connection = $options['connection']; if (!isset($options['proxy'])) { throw new ConfigException('No doctrine proxy settings set'); } if (!isset($options['proxy']['directory'])) { throw new ConfigException('You must set a proxy directory'); } $proxyDirectory = $options['proxy']['directory']; $proxyNamespace = 'Epixa\\Proxy'; if (isset($options['proxy']['namespace'])) { $proxyNamespace = $options['proxy']['namespace']; } $autoGenerateProxies = true; if (isset($options['proxy']['autoGenerate'])) { $autoGenerateProxies = $options['proxy']['autoGenerate']; } if (isset($options['cacheClass'])) { $cache = new $options['cacheClass'](); } else { $cache = new \Doctrine\Common\Cache\ArrayCache(); } $entityPaths = array(); if (isset($options['entityPaths'])) { $entityPaths = $options['entityPaths']; } $logger = null; if (isset($options['loggerClass'])) { $logger = new $options['loggerClass'](); } $config = new Configuration(); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $driverImpl = $config->newDefaultAnnotationDriver($entityPaths); $config->setMetadataDriverImpl($driverImpl); $config->setProxyDir($proxyDirectory); $config->setProxyNamespace($proxyNamespace); $config->setAutoGenerateProxyClasses($autoGenerateProxies); if ($logger) { $config->setSQLLogger($logger); } return EntityManager::create($connection, $config); }
public function testCreateSQLLoggerWithPreviousExistingLoggerChainsLoggers() { $originalLogger = $this->getMock('Doctrine\\DBAL\\Logging\\SQLLogger'); $originalLogger->expects($this->once())->method('startQuery')->with($this->equalTo('test query')); $injectedLogger = $this->getMock('Doctrine\\DBAL\\Logging\\DebugStack'); $injectedLogger->expects($this->once())->method('startQuery')->with($this->equalTo('test query')); $configuration = new ORMConfiguration(); $configuration->setSQLLogger($originalLogger); $this->services->setService('doctrine.configuration.orm_default', $configuration); $this->services->setService('custom_logger', $injectedLogger); $this->services->setService('Config', array('doctrine' => array('sql_logger_collector' => array('orm_default' => array('sql_logger' => 'custom_logger'))))); $this->factory->createService($this->services); /* @var $logger \Doctrine\DBAL\Logging\SQLLogger */ $logger = $configuration->getSQLLogger(); $logger->startQuery('test query'); }
public function __construct() { // load database configuration and custom config from CodeIgniter require APPPATH . 'config/database.php'; // Set up class loading. require_once APPPATH . 'libraries/Doctrine/Common/ClassLoader.php'; $doctrineClassLoader = new \Doctrine\Common\ClassLoader('Doctrine', APPPATH . 'libraries'); $doctrineClassLoader->register(); $entitiesClassLoader = new \Doctrine\Common\ClassLoader('models', rtrim(APPPATH, '/')); $entitiesClassLoader->register(); $proxiesClassLoader = new \Doctrine\Common\ClassLoader('Proxies', APPPATH . 'models'); $proxiesClassLoader->register(); $symfonyClassLoader = new \Doctrine\Common\ClassLoader('Symfony', APPPATH . 'libraries/Doctrine'); $symfonyClassLoader->register(); // Choose caching method based on application mode if (ENVIRONMENT == 'production') { $cache = new \Doctrine\Common\Cache\ApcCache(); } else { $cache = new \Doctrine\Common\Cache\ArrayCache(); } // Set some configuration options $config = new Configuration(); // Metadata driver $driverImpl = $config->newDefaultAnnotationDriver(APPPATH . 'models'); $config->setMetadataDriverImpl($driverImpl); // Caching $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); // Proxies $config->setProxyDir(APPPATH . 'models/Proxies'); $config->setProxyNamespace('Proxies'); if (ENVIRONMENT == 'development') { $config->setAutoGenerateProxyClasses(TRUE); } else { $config->setAutoGenerateProxyClasses(FALSE); } // SQL query logger if (DEBUGGING) { $logger = new \Doctrine\DBAL\Logging\EchoSQLLogger(); $config->setSQLLogger($logger); } // Database connection information $connectionOptions = array('driver' => 'pdo_mysql', 'user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database'], 'charset' => $db['default']['char_set'], 'driverOptions' => array('charset' => $db['default']['char_set'])); // Create EntityManager $this->em = EntityManager::create($connectionOptions, $config); }
/** * Factory method which creates an EntityManager. * * @return \Doctrine\ORM\EntityManager */ public function create() { $config = new Configuration(); $config->setClassMetadataFactoryName('TYPO3\\Flow\\Persistence\\Doctrine\\Mapping\\ClassMetadataFactory'); $cache = new \TYPO3\Flow\Persistence\Doctrine\CacheAdapter(); // must use ObjectManager in compile phase... $cache->setCache($this->objectManager->get('TYPO3\\Flow\\Cache\\CacheManager')->getCache('Flow_Persistence_Doctrine')); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $resultCache = new \TYPO3\Flow\Persistence\Doctrine\CacheAdapter(); // must use ObjectManager in compile phase... $resultCache->setCache($this->objectManager->get('TYPO3\\Flow\\Cache\\CacheManager')->getCache('Flow_Persistence_Doctrine_Results')); $config->setResultCacheImpl($resultCache); if (class_exists($this->settings['doctrine']['sqlLogger'])) { $config->setSQLLogger(new $this->settings['doctrine']['sqlLogger']()); } $eventManager = $this->buildEventManager(); $flowAnnotationDriver = $this->objectManager->get('TYPO3\\Flow\\Persistence\\Doctrine\\Mapping\\Driver\\FlowAnnotationDriver'); $config->setMetadataDriverImpl($flowAnnotationDriver); $proxyDirectory = \TYPO3\Flow\Utility\Files::concatenatePaths(array($this->environment->getPathToTemporaryDirectory(), 'Doctrine/Proxies')); \TYPO3\Flow\Utility\Files::createDirectoryRecursively($proxyDirectory); $config->setProxyDir($proxyDirectory); $config->setProxyNamespace('TYPO3\\Flow\\Persistence\\Doctrine\\Proxies'); $config->setAutoGenerateProxyClasses(FALSE); $entityManager = \Doctrine\ORM\EntityManager::create($this->settings['backendOptions'], $config, $eventManager); $flowAnnotationDriver->setEntityManager($entityManager); \Doctrine\DBAL\Types\Type::addType('objectarray', 'TYPO3\\Flow\\Persistence\\Doctrine\\DataTypes\\ObjectArray'); if (isset($this->settings['doctrine']['filters']) && is_array($this->settings['doctrine']['filters'])) { foreach ($this->settings['doctrine']['filters'] as $filterName => $filterClass) { $config->addFilter($filterName, $filterClass); $entityManager->getFilters()->enable($filterName); } } if (isset($this->settings['doctrine']['dql']) && is_array($this->settings['doctrine']['dql'])) { $this->applyDqlSettingsToConfiguration($this->settings['doctrine']['dql'], $config); } return $entityManager; }
public function __construct() { // Load configuration from CI - make sure to check for environment-specific config if (defined('ENVIRONMENT') and file_exists(APPPATH . 'config/' . ENVIRONMENT . '/database.php')) { require_once APPPATH . 'config/' . ENVIRONMENT . '/database.php'; } else { require_once APPPATH . 'config/database.php'; } // set up class loading. We don't have to use Doctrine's here require_once APPPATH . 'libraries/Doctrine/Common/ClassLoader.php'; $doctrineClassLoader = new ClassLoader('Doctrine', APPPATH . 'libraries'); $doctrineClassLoader->register(); $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, '/')); $entitiesClassLoader->register(); $proxiesClassLoader = new ClassLoader('Proxies', APPPATH . 'models/proxies'); $proxiesClassLoader->register(); // Set up caches $config = new Configuration(); $cache = new ArrayCache(); $config->setMetadataCacheImpl($cache); $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models/Entities')); $config->setMetadataDriverImpl($driverImpl); $config->setQueryCacheImpl($cache); // This line appears twice in documentationl not sure if needed? $config->setQueryCacheImpl($cache); // Proxy configuration $config->setProxyDir(APPPATH . '/models/proxies'); $config->setProxyNamespace('Proxies'); // Set up logger $logger = new EchoSQLLogger(); $config->setSQLLogger($logger); $config->setAutoGenerateProxyClasses(TRUE); // DB Connection $connectionOptions = array('driver' => 'pdo_mysql', 'user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database']); // Create EntityManager $this->em = EntityManager::create($connectionOptions, $config); }
public function setUp() { $reader = new AnnotationReader(); $driver = new AnnotationDriver($reader); $driver->addPaths(array(__DIR__ . '/Fixtures')); $config = new Configuration(); $config->setMetadataCacheImpl(new ArrayCache()); $config->setQueryCacheImpl(new ArrayCache()); $config->setProxyDir(sys_get_temp_dir()); $config->setProxyNamespace('SimpleThings\\EntityAudit\\Tests\\Proxies'); $config->setMetadataDriverImpl($driver); $conn = array('driver' => $GLOBALS['DOCTRINE_DRIVER'], 'memory' => $GLOBALS['DOCTRINE_MEMORY'], 'dbname' => $GLOBALS['DOCTRINE_DATABASE'], 'user' => $GLOBALS['DOCTRINE_USER'], 'password' => $GLOBALS['DOCTRINE_PASSWORD'], 'host' => $GLOBALS['DOCTRINE_HOST']); if (isset($GLOBALS['DOCTRINE_PATH'])) { $conn['path'] = $GLOBALS['DOCTRINE_PATH']; } $auditConfig = new AuditConfiguration(); $auditConfig->setCurrentUsername("beberlei"); $auditConfig->setAuditedEntityClasses($this->auditedEntities); $auditConfig->setGlobalIgnoreColumns(array('ignoreme')); $this->auditManager = new AuditManager($auditConfig); $this->auditManager->registerEvents($evm = new EventManager()); if (php_sapi_name() == 'cli' && isset($_SERVER['argv']) && (in_array('-v', $_SERVER['argv']) || in_array('--verbose', $_SERVER['argv']))) { $config->setSQLLogger(new EchoSQLLogger()); } $this->em = EntityManager::create($conn, $config, $evm); $schemaTool = new SchemaTool($this->em); $em = $this->em; try { $schemaTool->createSchema(array_map(function ($value) use($em) { return $em->getClassMetadata($value); }, $this->schemaEntities)); } catch (\Exception $e) { if ($GLOBALS['DOCTRINE_DRIVER'] != 'pdo_mysql' || !($e instanceof \PDOException && strpos($e->getMessage(), 'Base table or view already exists') !== false)) { throw $e; } } }
use Doctrine\ORM\Tools\Console\ConsoleRunner; use Doctrine\Common\ClassLoader, Doctrine\ORM\Configuration, Doctrine\ORM\EntityManager, Doctrine\Common\Cache\ArrayCache, Doctrine\DBAL\Logging\EchoSQLLogger; define('APPPATH', dirname(__FILE__) . DIRECTORY_SEPARATOR); require_once APPPATH . 'libraries/Doctrine/Common/ClassLoader.php'; $doctrineClassLoader = new ClassLoader('Doctrine', APPPATH . 'libraries'); $doctrineClassLoader->register(); $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, "/")); $entitiesClassLoader->register(); $proxiesClassLoader = new ClassLoader('Proxies', APPPATH . 'models/proxies'); $proxiesClassLoader->register(); // Set up caches $config = new Configuration(); $cache = new ArrayCache(); $config->setMetadataCacheImpl($cache); //$driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH.'models/Entities')); //$config->setMetadataDriverImpl($driverImpl); $config->setMetadataDriverImpl(new Doctrine\ORM\Mapping\Driver\XmlDriver(APPPATH . 'models')); $config->setQueryCacheImpl($cache); $config->setQueryCacheImpl($cache); // Proxy configuration $config->setProxyDir(APPPATH . '/models/proxies'); $config->setProxyNamespace('Proxies'); // Set up logger $logger = new EchoSQLLogger(); $config->setSQLLogger($logger); $config->setAutoGenerateProxyClasses(TRUE); // Database connection information $connectionOptions = array('driver' => 'pdo_mysql', 'user' => 'root', 'password' => 'fp87694fbr', 'host' => 'localhost', 'dbname' => 'mostratec'); // Create EntityManager $em = EntityManager::create($connectionOptions, $config); return ConsoleRunner::createHelperSet($em);
/** * @codeCoverageIgnore * Returns a new ORM Configuration. * * @param array $options Optional, the options to create the new Configuration * @return Configuration */ private static function getORMConfiguration(array $options = array(), LoggerInterface $logger = null, ContainerInterface $container = null) { $config = new Configuration(); $driverImpl = $config->newDefaultAnnotationDriver([], false); $config->setMetadataDriverImpl($driverImpl); if (isset($options['proxy_dir'])) { $config->setProxyDir($options['proxy_dir']); } if (isset($options['proxy_ns'])) { $config->setProxyNamespace($options['proxy_ns']); } if (isset($options['orm'])) { if (isset($options['orm']['proxy_namespace'])) { $config->setProxyNamespace($options['orm']['proxy_namespace']); } if (isset($options['orm']['proxy_dir'])) { $config->setProxyDir($options['orm']['proxy_dir']); } if (isset($options['orm']['auto_generate_proxy_classes'])) { $config->setAutoGenerateProxyClasses($options['orm']['auto_generate_proxy_classes']); } if (isset($options['orm']['metadata_cache_driver']) && is_array($options['orm']['metadata_cache_driver'])) { if (isset($options['orm']['metadata_cache_driver']['type'])) { if ('service' === $options['orm']['metadata_cache_driver']['type'] && isset($options['orm']['metadata_cache_driver']['id'])) { $serviceId = str_replace('@', '', $options['orm']['metadata_cache_driver']['id']); if (null !== $container && $container->has($serviceId)) { $config->setMetadataCacheImpl($container->get($serviceId)); } } } } if (isset($options['orm']['query_cache_driver']) && is_array($options['orm']['query_cache_driver'])) { if (isset($options['orm']['query_cache_driver']['type'])) { if ('service' === $options['orm']['query_cache_driver']['type'] && isset($options['orm']['query_cache_driver']['id'])) { $serviceId = str_replace('@', '', $options['orm']['query_cache_driver']['id']); if (null !== $container && $container->has($serviceId)) { $config->setQueryCacheImpl($container->get($serviceId)); } } } } } if ($logger instanceof SQLLogger) { $config->setSQLLogger($logger); } return self::addCustomFunctions($config, $options); }
protected function _initDoctrine() { $appDoctrineConfig = $this->getOption('doctrine'); $classLoader = new DoctrineClassLoader('Doctrine'); $classLoader->setIncludePath(realpath(APPLICATION_PATH . '/../library')); $classLoader->register(); $config = new DoctrineConfiguration(); if (isset($appDoctrineConfig['cache'])) { switch ($appDoctrineConfig['cache']) { case 'array': $cache = new DoctrineArrayCache(); break; case 'apc': $cache = new DoctrineApcCache(); break; } $config->setQueryCacheImpl($cache); $config->setMetadataCacheImpl($cache); } $proxyDir = empty($appDoctrineConfig['proxyDir']) ? APPLICATION_PATH . '/../library/Orm/Proxies' : $appDoctrineConfig['proxyDir']; $config->setProxyDir(realpath($proxyDir)); $config->setProxyNamespace('Orm\\Proxies'); $config->setAutoGenerateProxyClasses(false); $config->setEntityNamespaces(array('Orm\\Entity')); $config->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\StaticPHPDriver(realpath(APPLICATION_PATH . '/../library/Orm/Entity'))); //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); $config->setSQLLogger(null); $db = $this->getResource('db'); $dbConfig = $db->getConfig(); $connectionOptions = array('pdo' => $db->getConnection(), 'dbname' => $dbConfig['dbname']); $entityManager = DoctrineEntityManager::create($connectionOptions, $config); $entityManager->getConnection()->getConfiguration()->setSQLLogger(null); Registry::setEntityManager($entityManager); return $entityManager; }
/** * Setup SQL logger. * * @param \Doctrine\ORM\Configuration $config * @param array $options */ protected static function setupSQLLogger(Configuration &$config, array $options) { if ($options['sql_logger']) { $config->setSQLLogger($options['sql_logger']); } }
/** * {@inheritdoc} */ protected function createWithConfig(ContainerInterface $container, $configKey) { $config = $this->retrieveConfig($container, $configKey, 'configuration'); $configuration = new Configuration(); $configuration->setProxyDir($config['proxy_dir']); $configuration->setProxyNamespace($config['proxy_namespace']); $configuration->setAutoGenerateProxyClasses($config['auto_generate_proxy_classes']); $configuration->setEntityNamespaces($config['entity_namespaces']); $configuration->setCustomDatetimeFunctions($config['datetime_functions']); $configuration->setCustomStringFunctions($config['string_functions']); $configuration->setCustomNumericFunctions($config['numeric_functions']); $configuration->setCustomHydrationModes($config['custom_hydration_modes']); $configuration->setClassMetadataFactoryName($config['class_metadata_factory_name']); foreach ($config['named_queries'] as $name => $dql) { $configuration->addNamedQuery($name, $dql); } foreach ($config['named_native_queries'] as $name => $query) { $configuration->addNamedNativeQuery($name, $query['sql'], $query['rsm']); } foreach ($config['filters'] as $name => $className) { $configuration->addFilter($name, $className); } $configuration->setMetadataCacheImpl($this->retrieveDependency($container, $config['metadata_cache'], 'cache', CacheFactory::class)); $configuration->setQueryCacheImpl($this->retrieveDependency($container, $config['query_cache'], 'cache', CacheFactory::class)); $configuration->setResultCacheImpl($this->retrieveDependency($container, $config['result_cache'], 'cache', CacheFactory::class)); $configuration->setHydrationCacheImpl($this->retrieveDependency($container, $config['hydration_cache'], 'cache', CacheFactory::class)); $configuration->setMetadataDriverImpl($this->retrieveDependency($container, $config['driver'], 'driver', DriverFactory::class)); if (is_string($config['naming_strategy'])) { $configuration->setNamingStrategy($container->get($config['naming_strategy'])); } elseif (null !== $config['naming_strategy']) { $configuration->setNamingStrategy($config['naming_strategy']); } if (is_string($config['repository_factory'])) { $configuration->setRepositoryFactory($container->get($config['repository_factory'])); } elseif (null !== $config['repository_factory']) { $configuration->setRepositoryFactory($config['repository_factory']); } if (is_string($config['entity_listener_resolver'])) { $configuration->setEntityListenerResolver($container->get($config['entity_listener_resolver'])); } elseif (null !== $config['entity_listener_resolver']) { $configuration->setEntityListenerResolver($config['entity_listener_resolver']); } if (null !== $config['default_repository_class_name']) { $configuration->setDefaultRepositoryClassName($config['default_repository_class_name']); } if ($config['second_level_cache']['enabled']) { $regionsConfig = new RegionsConfiguration($config['second_level_cache']['default_lifetime'], $config['second_level_cache']['default_lock_lifetime']); foreach ($config['second_level_cache']['regions'] as $regionName => $regionConfig) { if (array_key_exists('lifetime', $regionConfig)) { $regionsConfig->setLifetime($regionName, $regionConfig['lifetime']); } if (array_key_exists('lock_lifetime', $regionConfig)) { $regionsConfig->setLockLifetime($regionName, $regionConfig['lock_lifetime']); } } $cacheFactory = new DefaultCacheFactory($regionsConfig, $configuration->getResultCacheImpl()); $cacheFactory->setFileLockRegionDirectory($config['second_level_cache']['file_lock_region_directory']); $cacheConfiguration = new CacheConfiguration(); $cacheConfiguration->setCacheFactory($cacheFactory); $cacheConfiguration->setRegionsConfiguration($regionsConfig); $configuration->setSecondLevelCacheEnabled(true); $configuration->setSecondLevelCacheConfiguration($cacheConfiguration); } if (is_string($config['sql_logger'])) { $configuration->setSQLLogger($container->get($config['sql_logger'])); } elseif (null !== $config['sql_logger']) { $configuration->setSQLLogger($config['sql_logger']); } return $configuration; }
/** * @param EntityManagerInterface $em * @param Configuration $configuration */ public function register(EntityManagerInterface $em, Configuration $configuration) { $debugStack = new DebugStack(); $configuration->setSQLLogger($debugStack); $this->clockwork->addDataSource(new DoctrineDataSource($debugStack, $em->getConnection()->getDriver()->getName())); }
/** * @param EntityManagerInterface $em * @param Configuration $configuration */ public function register(EntityManagerInterface $em, Configuration $configuration) { $logger = new DoctrineFileLogger($this->logger); $configuration->setSQLLogger($logger); }
/** * {@inheritDoc} */ protected function loadInstance() { $opts = $this->opts; $config = new DoctrineConfiguration(); // proxies $config->setAutoGenerateProxyClasses($opts['auto_generate_proxies']); $config->setProxyDir($opts['proxy_dir']); $config->setProxyNamespace($opts['proxy_namespace']); // entity namespaces $config->setEntityNamespaces($opts['entity_namespaces']); // add custom functions $config->setCustomDatetimeFunctions($opts['custom_datetime_functions']); $config->setCustomStringFunctions($opts['custom_string_functions']); $config->setCustomNumericFunctions($opts['custom_numeric_functions']); // custom queries foreach ($opts['named_queries'] as $query) { $config->addNamedQuery($query['name'], $query['dql']); } foreach ($opts['named_native_queries'] as $query) { $config->addNamedNativeQuery($query['name'], $query['sql'], new $query['rsm']()); } // caching $config->setQueryCacheImpl($this->queryCache); $config->setMetadataCacheImpl($this->metadataCache); $config->setResultCacheImpl($this->metadataCache); // logger $config->setSQLLogger($this->logger); // finally, the driver $config->setMetadataDriverImpl($this->metadataDriver); $this->instance = $config; }
protected function setupLogging(ServiceLocatorInterface $services, Configuration $config, $spec, $name) { $profiler = new Profiler($name); $profiler->getEventManager()->setSharedManager($services->get('SharedEventManager')); $profiler->setIsLogging($spec['log_sql']); $config->setSQLLogger($profiler); }
/** * @param EntityManagerInterface $em * @param Configuration $configuration */ public function register(EntityManagerInterface $em, Configuration $configuration) { $configuration->setSQLLogger(new EchoSQLLogger()); }
public function __construct() { // load database configuration from CodeIgniter require_once APPPATH . 'config/database.php'; include_once APPPATH . 'third_party/Doctrine/vendor/autoload.php'; // load the entities $entityClassLoader = new ClassLoader('Entity', APPPATH . 'models'); $entityClassLoader->register(); // load the proxy entities $proxiesClassLoader = new ClassLoader('Proxies', APPPATH . 'models'); $proxiesClassLoader->register(); // Set up the configuration $config = new Configuration(); // Set up caches if (ENVIRONMENT == 'development') { // set environment in index.php // set up simple array caching for development mode $cacheDriver = new \Doctrine\Common\Cache\ArrayCache(); } else { // set up caching with APC for production mode $redis = new Redis(); $redis->connect('redis_host', 'redis_port'); $cacheDriver = new \Doctrine\Common\Cache\RedisCache(); $cacheDriver->setRedis($redis); } $config->setMetadataCacheImpl($cacheDriver); $config->setQueryCacheImpl($cacheDriver); $driverImpl = $config->newDefaultAnnotationDriver(APPPATH . 'models/Entity'); $config->setMetadataDriverImpl($driverImpl); // Proxy configuration $config->setProxyDir(APPPATH . '/models/Proxies'); $config->setProxyNamespace('Proxies'); // Set up logger if (ENVIRONMENT == 'development') { $logger = new \Doctrine\DBAL\Logging\EchoSQLLogger(); $config->setSQLLogger($logger); } $config->setAutoGenerateProxyClasses(true); // only for development $connectionOptions = array('driver' => 'pdo_mysql', 'user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database'], 'charset' => $db['default']['char_set'], 'driverOptions' => array('charset' => $db['default']['char_set'])); $this->em = EntityManager::create($connectionOptions, $config); // $connection_options = array( // 'driver' => 'pdo_mysql', // 'user' => $db['default']['username'], // 'password' => $db['default']['password'], // 'host' => $db['default']['hostname'], // 'dbname' => $db['default']['database'], // 'charset' => $db['default']['char_set'], // 'driverOptions' => array( // 'charset' => $db['default']['char_set'], // ), // ); // // // With this configuration, your model files need to be in application/models/Entity // // e.g. Creating a new Entity\User loads the class from application/models/Entity/User.php // $models_namespace = 'Entity'; // $models_path = APPPATH . 'models'; // $proxies_dir = APPPATH . 'models/Proxies'; // $metadata_paths = array(APPPATH . 'models/Entity'); // // // Set $dev_mode to TRUE to disable caching while you develop // $dev_mode = true; // // // If you want to use a different metadata driver, change createAnnotationMetadataConfiguration // // to createXMLMetadataConfiguration or createYAMLMetadataConfiguration. // $config = Setup::createAnnotationMetadataConfiguration($metadata_paths, $dev_mode, $proxies_dir); // $this->em = EntityManager::create($connection_options, $config); // // $loader = new ClassLoader($models_namespace, $models_path); // $loader->register(); }
/** * Initializes the doctrine framework and * sets all required configuration options. * * @param none * @return nothing */ public static function initializeDoctrine() { $config = new Configuration(); $driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__)); $config->setMetadataDriverImpl($driverImpl); $connectionOptions = PartKeepr::createConnectionOptionsFromConfig(); switch (strtolower(PartKeeprConfiguration::getOption("partkeepr.cache.implementation", "default"))) { case "apc": $cache = new \Doctrine\Common\Cache\ApcCache(); break; case "xcache": if (php_sapi_name() !== "cli") { $cache = new \Doctrine\Common\Cache\XcacheCache(); } else { // For CLI SAPIs, revert to the ArrayCache as Xcache spits out strange warnings when running in CLI. $cache = new \Doctrine\Common\Cache\ArrayCache(); } break; case "memcache": $memcache = new \Memcache(); $memcache->connect(PartKeeprConfiguration::getOption("partkeepr.cache.memcache.host", "localhost"), PartKeeprConfiguration::getOption("partkeepr.cache.memcache.port", "11211")); $cache = new \Doctrine\Common\Cache\MemcacheCache(); $cache->setMemcache($memcache); break; case "default": case "auto": if (extension_loaded("xcache")) { $cache = new \Doctrine\Common\Cache\XcacheCache(); } else { if (extension_loaded("apc")) { $cache = new \Doctrine\Common\Cache\ApcCache(); } else { $cache = new \Doctrine\Common\Cache\ArrayCache(); } } break; case "none": $cache = new \Doctrine\Common\Cache\ArrayCache(); break; } $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $config->setProxyDir(self::getRootDirectory() . '/data/proxies'); $config->setProxyNamespace('Proxies'); $config->setEntityNamespaces(self::getEntityClasses()); $config->setAutoGenerateProxyClasses(false); if (PartKeeprConfiguration::getOption("partkeepr.database.echo_sql_log", false) === true) { $logger = new \Doctrine\DBAL\Logging\EchoSQLLogger(); $config->setSQLLogger($logger); } self::$entityManager = EntityManager::create($connectionOptions, $config); }
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']); }); }
/** * Configures the metadata configuration instance. * * @param Configuration $configuration * @param array $doctrineConfig * * @throws ORMException */ protected function configureMetadataConfiguration(Configuration $configuration, array $doctrineConfig) { if (isset($doctrineConfig['filters'])) { foreach ($doctrineConfig['filters'] as $name => $filter) { $configuration->addFilter($name, $filter['class']); } } if (isset($doctrineConfig['logger'])) { $configuration->setSQLLogger($doctrineConfig['logger']); } if (isset($doctrineConfig['proxy']) && isset($doctrineConfig['proxy']['auto_generate'])) { $configuration->setAutoGenerateProxyClasses($doctrineConfig['proxy']['auto_generate']); } if (isset($doctrineConfig['proxy']) && isset($doctrineConfig['proxy']['namespace'])) { $configuration->setProxyNamespace($doctrineConfig['proxy']['namespace']); } if (isset($doctrineConfig['repository'])) { $configuration->setDefaultRepositoryClassName($doctrineConfig['repository']); } $namingStrategy = array_get($doctrineConfig, 'naming_strategy', 'Nord\\Lumen\\Doctrine\\ORM\\NamingStrategy'); $configuration->setNamingStrategy(new $namingStrategy()); }
/** * Factory method which creates an EntityManager. * * @return EntityManager * @throws \TYPO3\Flow\Configuration\Exception\InvalidConfigurationException */ public function create() { $config = new Configuration(); $config->setClassMetadataFactoryName(Mapping\ClassMetadataFactory::class); $cache = new CacheAdapter(); // must use ObjectManager in compile phase... $cache->setCache($this->objectManager->get(CacheManager::class)->getCache('Flow_Persistence_Doctrine')); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $resultCache = new CacheAdapter(); // must use ObjectManager in compile phase... $resultCache->setCache($this->objectManager->get(CacheManager::class)->getCache('Flow_Persistence_Doctrine_Results')); $config->setResultCacheImpl($resultCache); if (is_string($this->settings['doctrine']['sqlLogger']) && class_exists($this->settings['doctrine']['sqlLogger'])) { $configuredSqlLogger = $this->settings['doctrine']['sqlLogger']; $sqlLoggerInstance = new $configuredSqlLogger(); if ($sqlLoggerInstance instanceof SQLLogger) { $config->setSQLLogger($sqlLoggerInstance); } else { throw new InvalidConfigurationException(sprintf('TYPO3.Flow.persistence.doctrine.sqlLogger must point to a \\Doctrine\\DBAL\\Logging\\SQLLogger implementation, %s given.', get_class($sqlLoggerInstance)), 1426150388); } } $eventManager = $this->buildEventManager(); $flowAnnotationDriver = $this->objectManager->get(Mapping\Driver\FlowAnnotationDriver::class); $config->setMetadataDriverImpl($flowAnnotationDriver); $proxyDirectory = Files::concatenatePaths(array($this->environment->getPathToTemporaryDirectory(), 'Doctrine/Proxies')); Files::createDirectoryRecursively($proxyDirectory); $config->setProxyDir($proxyDirectory); $config->setProxyNamespace('TYPO3\\Flow\\Persistence\\Doctrine\\Proxies'); $config->setAutoGenerateProxyClasses(false); // Set default host to 127.0.0.1 if there is no host configured but a dbname if (empty($this->settings['backendOptions']['host']) && !empty($this->settings['backendOptions']['dbname'])) { $this->settings['backendOptions']['host'] = '127.0.0.1'; } // The following code tries to connect first, if that succeeds, all is well. If not, the platform is fetched directly from the // driver - without version checks to the database server (to which no connection can be made) - and is added to the config // which is then used to create a new connection. This connection will then return the platform directly, without trying to // detect the version it runs on, which fails if no connection can be made. But the platform is used even if no connection can // be made, which was no problem with Doctrine DBAL 2.3. And then came version-aware drivers and platforms... $connection = DriverManager::getConnection($this->settings['backendOptions'], $config, $eventManager); try { $connection->connect(); } catch (ConnectionException $exception) { $settings = $this->settings['backendOptions']; $settings['platform'] = $connection->getDriver()->getDatabasePlatform(); $connection = DriverManager::getConnection($settings, $config, $eventManager); } $entityManager = EntityManager::create($connection, $config, $eventManager); $flowAnnotationDriver->setEntityManager($entityManager); if (isset($this->settings['doctrine']['dbal']['mappingTypes']) && is_array($this->settings['doctrine']['dbal']['mappingTypes'])) { foreach ($this->settings['doctrine']['dbal']['mappingTypes'] as $typeName => $typeConfiguration) { Type::addType($typeName, $typeConfiguration['className']); $entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping($typeConfiguration['dbType'], $typeName); } } if (isset($this->settings['doctrine']['filters']) && is_array($this->settings['doctrine']['filters'])) { foreach ($this->settings['doctrine']['filters'] as $filterName => $filterClass) { $config->addFilter($filterName, $filterClass); $entityManager->getFilters()->enable($filterName); } } if (isset($this->settings['doctrine']['dql']) && is_array($this->settings['doctrine']['dql'])) { $this->applyDqlSettingsToConfiguration($this->settings['doctrine']['dql'], $config); } return $entityManager; }
/** * Initializes the doctrine framework and * sets all required configuration options. * * @param none * @return nothing */ public static function initializeDoctrine () { $config = new Configuration; $driverImpl = $config->newDefaultAnnotationDriver( array(__DIR__) //array(__DIR__."/Session") ); $config->setMetadataDriverImpl($driverImpl); $connectionOptions = array( 'driver' => PartKeeprConfiguration::getOption("partkeepr.database.driver","pdo_mysql"), 'dbname' => PartKeeprConfiguration::getOption("partkeepr.database.dbname", "partkeepr"), 'user' => PartKeeprConfiguration::getOption("partkeepr.database.username", "partkeepr"), 'password' => PartKeeprConfiguration::getOption("partkeepr.database.password", "partkeepr"), 'host' => PartKeeprConfiguration::getOption("partkeepr.database.hostname", "localhost") ); $cache = new \Doctrine\Common\Cache\ApcCache(); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $config->setProxyDir(dirname(dirname(dirname(__DIR__))) . '/Proxies'); $config->setProxyNamespace('Proxies'); $config->setEntityNamespaces(self::getEntityClasses()); $config->setAutoGenerateProxyClasses(false); if (PartKeeprConfiguration::getOption("partkeepr.database.echo_sql_log", false) === true) { $logger = new \Doctrine\DBAL\Logging\EchoSQLLogger(); $config->setSQLLogger($logger); } self::$entityManager = EntityManager::create($connectionOptions, $config); }