protected static function getEntityManager($options) { $config = new \Doctrine\ORM\Configuration(); // Handling for class names specified as platform types. if ($options['conn']['platform']) { $class_obj = new \ReflectionClass($options['conn']['platform']); $options['conn']['platform'] = $class_obj->newInstance(); } // Special handling for the utf8mb4 type. if ($options['conn']['driver'] == 'pdo_mysql' && $options['conn']['charset'] == 'utf8mb4') { $options['conn']['platform'] = new \DF\Doctrine\Platform\MysqlUnicode(); } $metadata_driver = $config->newDefaultAnnotationDriver($options['modelPath']); $config->setMetadataDriverImpl($metadata_driver); $cache = new \DF\Doctrine\Cache(); // $cache->setNamespace('doctrine_'); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $config->setResultCacheImpl($cache); $config->setProxyDir($options['proxyPath']); $config->setProxyNamespace($options['proxyNamespace']); if (isset($options['conn']['debug']) && $options['conn']['debug']) { $config->setSQLLogger(new \DF\Doctrine\Logger\EchoSQL()); } $config->addFilter('softdelete', '\\DF\\Doctrine\\Filter\\SoftDelete'); $config->addCustomNumericFunction('RAND', '\\DF\\Doctrine\\Functions\\Rand'); $evm = new \Doctrine\Common\EventManager(); $em = \Doctrine\ORM\EntityManager::create($options['conn'], $config, $evm); $em->getFilters()->enable("softdelete"); // Try the connection before rendering the page. $em->getConnection()->connect(); return $em; }
public function setUp() { $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setProxyDir(__DIR__ . '/_files'); $config->setProxyNamespace('DoctrineExtensions\\Paginate\\Proxies'); $conn = array('driver' => 'pdo_sqlite', 'memory' => true); $config->addCustomNumericFunction('DATEDIFF', 'DoctrineExtensions\\Query\\Mysql\\DateDiff'); $config->addCustomDatetimeFunction('DATE_ADD', 'DoctrineExtensions\\Query\\Mysql\\DateAdd'); $this->entityManager = \Doctrine\ORM\EntityManager::create($conn, $config); }
public function setUp() { $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setProxyDir($GLOBALS['doctrine2-proxies-path']); $config->setProxyNamespace($GLOBALS['doctrine2-proxies-namespace']); $config->setAutoGenerateProxyClasses(true); $driver = $config->newDefaultAnnotationDriver($GLOBALS['doctrine2-entities-path']); $config->setMetadataDriverImpl($driver); $conn = array('driver' => 'pdo_sqlite', 'memory' => true); $config->addCustomNumericFunction('SIN', 'DoctrineExtensions\\Query\\Mysql\\Sin'); $config->addCustomNumericFunction('ASIN', 'DoctrineExtensions\\Query\\Mysql\\Asin'); $config->addCustomNumericFunction('COS', 'DoctrineExtensions\\Query\\Mysql\\Cos'); $config->addCustomNumericFunction('ACOS', 'DoctrineExtensions\\Query\\Mysql\\Acos'); $config->addCustomNumericFunction('COT', 'DoctrineExtensions\\Query\\Mysql\\Cot'); $config->addCustomNumericFunction('TAN', 'DoctrineExtensions\\Query\\Mysql\\Tan'); $config->addCustomNumericFunction('ATAN', 'DoctrineExtensions\\Query\\Mysql\\Atan'); $config->addCustomNumericFunction('ATAN2', 'DoctrineExtensions\\Query\\Mysql\\Atan2'); $config->addCustomNumericFunction('DEGREES', 'DoctrineExtensions\\Query\\Mysql\\Degrees'); $config->addCustomNumericFunction('RADIANS', 'DoctrineExtensions\\Query\\Mysql\\Radians'); $this->entityManager = \Doctrine\ORM\EntityManager::create($conn, $config); }
public function setUp() { $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setProxyDir($GLOBALS['doctrine2-proxies-path']); $config->setProxyNamespace($GLOBALS['doctrine2-proxies-namespace']); $config->setAutoGenerateProxyClasses(true); $driver = $config->newDefaultAnnotationDriver($GLOBALS['doctrine2-entities-path']); $config->setMetadataDriverImpl($driver); $conn = array('driver' => 'pdo_sqlite', 'memory' => true); $config->addCustomNumericFunction('DATEDIFF', 'DoctrineExtensions\\Query\\Mysql\\DateDiff'); $config->addCustomDatetimeFunction('DATE_ADD', 'DoctrineExtensions\\Query\\Mysql\\DateAdd'); $config->addCustomStringFunction('STR_TO_DATE', 'DoctrineExtensions\\Query\\MySql\\StrToDate'); $config->addCustomStringFunction('FIND_IN_SET', 'DoctrineExtensions\\Query\\MySql\\FindInSet'); $this->entityManager = \Doctrine\ORM\EntityManager::create($conn, $config); }
/** * Initialize ORM Configuration. * * @param array $config ORM EntityManager configuration. * * @return Doctrine\ORM\Configuration */ private function startORMConfiguration(array $config = array()) { $configClass = $config['configurationClass']; $configuration = new $configClass(); $configuration = new \Doctrine\ORM\Configuration(); // Entity Namespaces configuration foreach ($config['entityNamespaces'] as $alias => $namespace) { $configuration->addEntityNamespace($alias, $namespace); } // Proxy configuration $configuration->setAutoGenerateProxyClasses(!in_array($config['proxy']['autoGenerateClasses'], array("0", "false", false))); $configuration->setProxyNamespace($config['proxy']['namespace']); $configuration->setProxyDir($config['proxy']['dir']); // Cache configuration $configuration->setMetadataCacheImpl($this->getCacheInstance($config['metadataCache'])); $configuration->setResultCacheImpl($this->getCacheInstance($config['resultCache'])); $configuration->setQueryCacheImpl($this->getCacheInstance($config['queryCache'])); // Metadata configuration $configuration->setMetadataDriverImpl($this->startORMMetadata($config['metadataDrivers'])); // DQL Functions configuration $dqlFunctions = $config['DQLFunctions']; foreach ($dqlFunctions['datetime'] as $name => $className) { $configuration->addCustomDatetimeFunction($name, $className); } foreach ($dqlFunctions['numeric'] as $name => $className) { $configuration->addCustomNumericFunction($name, $className); } foreach ($dqlFunctions['string'] as $name => $className) { $configuration->addCustomStringFunction($name, $className); } return $configuration; }
/** * Gets the 'doctrine.orm.default_entity_manager' service. * * This service is shared. * This method always returns the same instance of the service. * * @param bool $lazyLoad whether to try lazy-loading the service with a proxy * * @return \Doctrine\ORM\EntityManager A Doctrine\ORM\EntityManager instance */ protected function getDoctrine_Orm_DefaultEntityManagerService($lazyLoad = true) { $a = $this->get('annotation_reader'); $b = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($a, array(0 => $this->targetDirs[3] . '/vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity', 1 => $this->targetDirs[3] . '/vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Entity', 2 => $this->targetDirs[3] . '/vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity', 3 => $this->targetDirs[3] . '/vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity', 4 => $this->targetDirs[3] . '/vendor/7rin0/bigfoot-core-bundle/Bigfoot/Bundle/CoreBundle/Entity', 5 => $this->targetDirs[3] . '/vendor/7rin0/bigfoot-context-bundle/Bigfoot/Bundle/ContextBundle/Entity', 6 => $this->targetDirs[3] . '/vendor/7rin0/bigfoot-navigation-bundle/Bigfoot/Bundle/NavigationBundle/Entity', 7 => $this->targetDirs[3] . '/vendor/7rin0/bigfoot-user-bundle/Bigfoot/Bundle/UserBundle/Entity', 8 => $this->targetDirs[3] . '/vendor/7rin0/bigfoot-content-bundle/Bigfoot/Bundle/ContentBundle/Entity', 9 => $this->targetDirs[3] . '/vendor/7rin0/bigfoot-media-bundle/Bigfoot/Bundle/MediaBundle/Entity')); $c = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain(); $c->addDriver($b, 'Gedmo\\Translatable\\Entity'); $c->addDriver($b, 'Gedmo\\Translator\\Entity'); $c->addDriver($b, 'Gedmo\\Loggable\\Entity'); $c->addDriver($b, 'Gedmo\\Tree\\Entity'); $c->addDriver($b, 'Bigfoot\\Bundle\\CoreBundle\\Entity'); $c->addDriver($b, 'Bigfoot\\Bundle\\ContextBundle\\Entity'); $c->addDriver($b, 'Bigfoot\\Bundle\\NavigationBundle\\Entity'); $c->addDriver($b, 'Bigfoot\\Bundle\\UserBundle\\Entity'); $c->addDriver($b, 'Bigfoot\\Bundle\\ContentBundle\\Entity'); $c->addDriver($b, 'Bigfoot\\Bundle\\MediaBundle\\Entity'); $d = new \Doctrine\ORM\Configuration(); $d->setEntityNamespaces(array('GedmoTranslatable' => 'Gedmo\\Translatable\\Entity', 'GedmoTranslator' => 'Gedmo\\Translator\\Entity', 'GedmoLoggable' => 'Gedmo\\Loggable\\Entity', 'GedmoTree' => 'Gedmo\\Tree\\Entity', 'BigfootCoreBundle' => 'Bigfoot\\Bundle\\CoreBundle\\Entity', 'BigfootContextBundle' => 'Bigfoot\\Bundle\\ContextBundle\\Entity', 'BigfootNavigationBundle' => 'Bigfoot\\Bundle\\NavigationBundle\\Entity', 'BigfootUserBundle' => 'Bigfoot\\Bundle\\UserBundle\\Entity', 'BigfootContentBundle' => 'Bigfoot\\Bundle\\ContentBundle\\Entity', 'BigfootMediaBundle' => 'Bigfoot\\Bundle\\MediaBundle\\Entity')); $d->setMetadataCacheImpl($this->get('doctrine_cache.providers.doctrine.orm.default_metadata_cache')); $d->setQueryCacheImpl($this->get('doctrine_cache.providers.doctrine.orm.default_query_cache')); $d->setResultCacheImpl($this->get('doctrine_cache.providers.doctrine.orm.default_result_cache')); $d->setMetadataDriverImpl($c); $d->setProxyDir(__DIR__ . '/doctrine/orm/Proxies'); $d->setProxyNamespace('Proxies'); $d->setAutoGenerateProxyClasses(true); $d->setClassMetadataFactoryName('Doctrine\\ORM\\Mapping\\ClassMetadataFactory'); $d->setDefaultRepositoryClassName('Doctrine\\ORM\\EntityRepository'); $d->setNamingStrategy(new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy()); $d->setQuoteStrategy(new \Doctrine\ORM\Mapping\DefaultQuoteStrategy()); $d->setEntityListenerResolver($this->get('doctrine.orm.default_entity_listener_resolver')); $d->addCustomStringFunction('regexp', 'Bigfoot\\Bundle\\CoreBundle\\ORM\\Doctrine\\Query\\MySQL\\Regexp'); $d->addCustomStringFunction('substring_index', 'Bigfoot\\Bundle\\CoreBundle\\ORM\\Doctrine\\Query\\MySQL\\SubstringIndex'); $d->addCustomStringFunction('greatest', 'Bigfoot\\Bundle\\CoreBundle\\ORM\\Doctrine\\Query\\MySQL\\Greatest'); $d->addCustomNumericFunction('acos', 'Bigfoot\\Bundle\\CoreBundle\\ORM\\Acos'); $d->addCustomNumericFunction('cos', 'Bigfoot\\Bundle\\CoreBundle\\ORM\\Cos'); $d->addCustomNumericFunction('sin', 'Bigfoot\\Bundle\\CoreBundle\\ORM\\Sin'); $d->addCustomNumericFunction('radians', 'Bigfoot\\Bundle\\CoreBundle\\ORM\\Radians'); $d->addCustomNumericFunction('GEO_DISTANCE', 'Craue\\GeoBundle\\Doctrine\\Query\\Mysql\\GeoDistance'); $d->addCustomNumericFunction('GEO_DISTANCE_BY_POSTAL_CODE', 'Craue\\GeoBundle\\Doctrine\\Query\\Mysql\\GeoDistanceByPostalCode'); $d->addFilter('softdeleteable', 'Gedmo\\SoftDeleteable\\Filter\\SoftDeleteableFilter'); $this->services['doctrine.orm.default_entity_manager'] = $instance = \Doctrine\ORM\EntityManager::create($this->get('doctrine.dbal.default_connection'), $d); $this->get('doctrine.orm.default_manager_configurator')->configure($instance); return $instance; }
/** * Initialize auto loader of Doctrine. * * @return \Doctrine\ORM\EntityManager */ public static function init($config) { self::optionsContainDSN($config); $vendor = VENDOR_PATH . '/doctrine/common/lib/'; // ensure doctrine2 exists in the libraries folder if (is_file($vendor . 'Doctrine/Common/ClassLoader.php') === false) { throw new \Koch\Exception\Exception('Doctrine2 not found. Check Libraries Folder.', 100); } // get isolated loader require $vendor . 'Doctrine/Common/ClassLoader.php'; // setup autoloaders with namespace and path to search in $classLoader = new \Doctrine\Common\ClassLoader('Doctrine', VENDOR_PATH); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Symfony', VENDOR_PATH . 'Doctrine/Symfony'); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Entity', APPLICATION_PATH . 'Doctrine'); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Repository', APPLICATION_PATH . 'Doctrine'); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Proxy', APPLICATION_PATH . 'Doctrine'); $classLoader->register(); // include Doctrine Extensions $classLoader = new \Doctrine\Common\ClassLoader('doctrine-extensions', VENDOR_PATH . 'gedmo/doctrine-extensions/lib/Gedmo'); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', VENDOR_PATH . 'beberlei/DoctrineExtensions/lib'); $classLoader->register(); // fetch doctrine config handler for configuring $D2Config = new \Doctrine\ORM\Configuration(); // fetch cache driver - APC in production and Array in development mode if (extension_loaded('apc') and DEBUG === false) { $cache = new \Doctrine\Common\Cache\ApcCache(); } else { $cache = new \Doctrine\Common\Cache\ArrayCache(); } // set cache driver $D2Config->setMetadataCacheImpl($cache); $D2Config->setQueryCacheImpl($cache); // set annotation driver for entities $D2Config->setMetadataDriverImpl($D2Config->newDefaultAnnotationDriver(self::getModelPathsForAllModules())); /* * This is slow like hell, because getAllClassNames traverses all * dirs and files and includes them. Its a workaround, till i find * a better way to acquire all the models. * @todo optimize this for performance reasons */ $D2Config->getMetadataDriverImpl()->getAllClassNames(); #\Koch\Debug\Debug::firebug($config->getMetadataDriverImpl()->getAllClassNames()); // set proxy dirs $D2Config->setProxyDir(APPLICATION_PATH . 'Doctrine'); $D2Config->setProxyNamespace('Proxy'); // regenerate proxies only in debug and not in production mode if (DEBUG === true) { $D2Config->setAutoGenerateProxyClasses(true); } else { $D2Config->setAutoGenerateProxyClasses(false); } // use main configuration values for setting up the connection $connectionOptions = ['driver' => $config['database']['driver'], 'user' => $config['database']['user'], 'password' => $config['database']['password'], 'dbname' => $config['database']['dbname'], 'host' => $config['database']['host'], 'charset' => $config['database']['charset'], 'driverOptions' => ['charset' => $config['database']['charset']]]; // set up Logger #$config->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger); /* * Events */ $event = new \Doctrine\Common\EventManager(); /* * Database Prefix * * The constant definition is for building (raw) sql queries manually. * The database prefixing is registered via an event. */ define('DB_PREFIX', $config['database']['prefix']); $tablePrefix = new TablePrefix(DB_PREFIX); $event->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix); /* * Custom Functions * * We need some more functions for MySQL, like RAND for random values. */ $D2Config->addCustomNumericFunction('RAND', 'Koch\\Doctrine\\Extensions\\Query\\Mysql\\Rand'); // Entity manager $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $D2Config, $event); // set DBAL DebugStack Logger (also needed for counting queries) if (defined('DEBUG') and DEBUG === 1) { self::$sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack(); $em->getConfiguration()->setSQLLogger(self::$sqlLoggerStack); // Echo SQL Queries directly on the page. $em->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); } self::$em = $em; // the D2 initalization is done, remove vars to safe memory unset($config, $em, $event, $cache, $classLoader, $D2Config); return self::$em; }
/** * Gets the 'doctrine.orm.default_entity_manager' service. * * This service is shared. * This method always returns the same instance of the service. * * @return \Doctrine\ORM\EntityManager A Doctrine\ORM\EntityManager instance. */ protected function getDoctrine_Orm_DefaultEntityManagerService() { $a = new \Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver(array(($this->targetDirs[3].'/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/doctrine') => 'FOS\\UserBundle\\Entity')); $a->setGlobalBasename('mapping'); $b = new \Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver(array(($this->targetDirs[3].'/src/SeekerPlus/UserBundle/Resources/config/doctrine') => 'SeekerPlus\\UserBundle\\Entity', ($this->targetDirs[3].'/src/SeekerPlus/AdsmanagerBundle/Resources/config/doctrine') => 'SeekerPlus\\AdsmanagerBundle\\Entity', ($this->targetDirs[3].'/src/SeekerPlus/BannerBundle/Resources/config/doctrine') => 'SeekerPlus\\BannerBundle\\Entity')); $b->setGlobalBasename('mapping'); $c = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain(); $c->addDriver($a, 'FOS\\UserBundle\\Entity'); $c->addDriver($b, 'SeekerPlus\\UserBundle\\Entity'); $c->addDriver($b, 'SeekerPlus\\AdsmanagerBundle\\Entity'); $c->addDriver($b, 'SeekerPlus\\BannerBundle\\Entity'); $d = new \Doctrine\ORM\Configuration(); $d->setEntityNamespaces(array('FOSUserBundle' => 'FOS\\UserBundle\\Entity', 'UserBundle' => 'SeekerPlus\\UserBundle\\Entity', 'AdsmanagerBundle' => 'SeekerPlus\\AdsmanagerBundle\\Entity', 'BannerBundle' => 'SeekerPlus\\BannerBundle\\Entity')); $d->setMetadataCacheImpl($this->get('doctrine_cache.providers.doctrine.orm.default_metadata_cache')); $d->setQueryCacheImpl($this->get('doctrine_cache.providers.doctrine.orm.default_query_cache')); $d->setResultCacheImpl($this->get('doctrine_cache.providers.doctrine.orm.default_result_cache')); $d->setMetadataDriverImpl($c); $d->setProxyDir((__DIR__.'/doctrine/orm/Proxies')); $d->setProxyNamespace('Proxies'); $d->setAutoGenerateProxyClasses(true); $d->setClassMetadataFactoryName('Doctrine\\ORM\\Mapping\\ClassMetadataFactory'); $d->setDefaultRepositoryClassName('Doctrine\\ORM\\EntityRepository'); $d->setNamingStrategy(new \Doctrine\ORM\Mapping\DefaultNamingStrategy()); $d->setQuoteStrategy(new \Doctrine\ORM\Mapping\DefaultQuoteStrategy()); $d->setEntityListenerResolver($this->get('doctrine.orm.default_entity_listener_resolver')); $d->addCustomNumericFunction('acos', 'Swis\\Bundle\\DatabaseExtraBundle\\DQL\\Acos'); $d->addCustomNumericFunction('cos', 'Swis\\Bundle\\DatabaseExtraBundle\\DQL\\Cos'); $d->addCustomNumericFunction('radians', 'Swis\\Bundle\\DatabaseExtraBundle\\DQL\\Radians'); $d->addCustomNumericFunction('sin', 'Swis\\Bundle\\DatabaseExtraBundle\\DQL\\Sin'); $d->addCustomNumericFunction('round', 'Swis\\Bundle\\DatabaseExtraBundle\\DQL\\Round'); $this->services['doctrine.orm.default_entity_manager'] = $instance = \Doctrine\ORM\EntityManager::create($this->get('doctrine.dbal.default_connection'), $d); $this->get('doctrine.orm.default_manager_configurator')->configure($instance); return $instance; }
/** * Gets the 'doctrine.orm.default_entity_manager' service. * * This service is shared. * This method always returns the same instance of the service. * * @return \Doctrine\ORM\EntityManager A Doctrine\ORM\EntityManager instance. */ protected function getDoctrine_Orm_DefaultEntityManagerService() { $a = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain(); $a->addDriver(new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($this->get('annotation_reader'), array(0 => $this->targetDirs[3] . '/src/ServiceBundle/Entity')), 'ServiceBundle\\Entity'); $b = new \Doctrine\ORM\Configuration(); $b->setEntityNamespaces(array('ServiceBundle' => 'ServiceBundle\\Entity')); $b->setMetadataCacheImpl($this->get('doctrine_cache.providers.doctrine.orm.default_metadata_cache')); $b->setQueryCacheImpl($this->get('doctrine_cache.providers.doctrine.orm.default_query_cache')); $b->setResultCacheImpl($this->get('doctrine_cache.providers.doctrine.orm.default_result_cache')); $b->setMetadataDriverImpl($a); $b->setProxyDir(__DIR__ . '/doctrine/orm/Proxies'); $b->setProxyNamespace('Proxies'); $b->setAutoGenerateProxyClasses(true); $b->setClassMetadataFactoryName('Doctrine\\ORM\\Mapping\\ClassMetadataFactory'); $b->setDefaultRepositoryClassName('Doctrine\\ORM\\EntityRepository'); $b->setNamingStrategy(new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy()); $b->setQuoteStrategy(new \Doctrine\ORM\Mapping\DefaultQuoteStrategy()); $b->setEntityListenerResolver($this->get('doctrine.orm.default_entity_listener_resolver')); $b->addCustomStringFunction('charlength', 'DoctrineExtensions\\Query\\Mysql\\CharLength'); $b->addCustomStringFunction('concat_ws', 'DoctrineExtensions\\Query\\Mysql\\ConcatWs'); $b->addCustomStringFunction('countif', 'DoctrineExtensions\\Query\\Mysql\\CountIf'); $b->addCustomStringFunction('degrees', 'DoctrineExtensions\\Query\\Mysql\\Degrees'); $b->addCustomStringFunction('field', 'DoctrineExtensions\\Query\\Mysql\\Field'); $b->addCustomStringFunction('findinset', 'DoctrineExtensions\\Query\\Mysql\\FindInSet'); $b->addCustomStringFunction('groupconcat', 'DoctrineExtensions\\Query\\Mysql\\GroupConcat'); $b->addCustomStringFunction('ifelse', 'DoctrineExtensions\\Query\\Mysql\\IfElse'); $b->addCustomStringFunction('ifnull', 'DoctrineExtensions\\Query\\Mysql\\IfNull'); $b->addCustomStringFunction('matchagainst', 'DoctrineExtensions\\Query\\Mysql\\MatchAgainst'); $b->addCustomStringFunction('md5', 'DoctrineExtensions\\Query\\Mysql\\Md5'); $b->addCustomStringFunction('month', 'DoctrineExtensions\\Query\\Mysql\\Month'); $b->addCustomStringFunction('monthname', 'DoctrineExtensions\\Query\\Mysql\\MonthName'); $b->addCustomStringFunction('nullif', 'DoctrineExtensions\\Query\\Mysql\\NullIf'); $b->addCustomStringFunction('radians', 'DoctrineExtensions\\Query\\Mysql\\Radians'); $b->addCustomStringFunction('sha1', 'DoctrineExtensions\\Query\\Mysql\\Sha1'); $b->addCustomStringFunction('sha2', 'DoctrineExtensions\\Query\\Mysql\\Sha2'); $b->addCustomNumericFunction('acos', 'DoctrineExtensions\\Query\\Mysql\\Acos'); $b->addCustomNumericFunction('asin', 'DoctrineExtensions\\Query\\Mysql\\Asin'); $b->addCustomNumericFunction('atan2', 'DoctrineExtensions\\Query\\Mysql\\Atan2'); $b->addCustomNumericFunction('atan', 'DoctrineExtensions\\Query\\Mysql\\Atan'); $b->addCustomNumericFunction('cos', 'DoctrineExtensions\\Query\\Mysql\\Cos'); $b->addCustomNumericFunction('cot', 'DoctrineExtensions\\Query\\Mysql\\Cot'); $b->addCustomNumericFunction('round', 'DoctrineExtensions\\Query\\Mysql\\Round'); $b->addCustomNumericFunction('sin', 'DoctrineExtensions\\Query\\Mysql\\Sin'); $b->addCustomNumericFunction('tan', 'DoctrineExtensions\\Query\\Mysql\\Tan'); $b->addCustomNumericFunction('time_diff', 'DoctrineExtensions\\Query\\Mysql\\TimeDiff'); $b->addCustomDatetimeFunction('date', 'DoctrineExtensions\\Query\\Mysql\\Date'); $b->addCustomDatetimeFunction('dateadd', 'DoctrineExtensions\\Query\\Mysql\\DateAdd'); $b->addCustomDatetimeFunction('datediff', 'DoctrineExtensions\\Query\\Mysql\\DateDiff'); $b->addCustomDatetimeFunction('date_format', 'DoctrineExtensions\\Query\\Mysql\\DateFormat'); $b->addCustomDatetimeFunction('day', 'DoctrineExtensions\\Query\\Mysql\\Day'); $b->addCustomDatetimeFunction('dayname', 'DoctrineExtensions\\Query\\Mysql\\DayName'); $b->addCustomDatetimeFunction('strtodate', 'DoctrineExtensions\\Query\\Mysql\\StrToDate'); $b->addCustomDatetimeFunction('timestampdiff', 'DoctrineExtensions\\Query\\Mysql\\TimestampDiff'); $b->addCustomDatetimeFunction('week', 'DoctrineExtensions\\Query\\Mysql\\Week'); $b->addCustomDatetimeFunction('year', 'DoctrineExtensions\\Query\\Mysql\\Year'); $b->addCustomDatetimeFunction('month', 'DoctrineExtensions\\Query\\Mysql\\Month'); $this->services['doctrine.orm.default_entity_manager'] = $instance = \Doctrine\ORM\EntityManager::create($this->get('doctrine.dbal.default_connection'), $b); $this->get('doctrine.orm.default_manager_configurator')->configure($instance); return $instance; }
/** * Initialize auto loader of Doctrine * * @return Doctrine_Enitity_Manager */ public static function init($clansuite_config) { self::checkDataSourceName($clansuite_config); // ensure doctrine2 exists in the libraries folder if (is_file(ROOT_LIBRARIES . 'Doctrine/Common/ClassLoader.php') === false) { throw new Koch_Exception('Doctrine2 not found. Check Libraries Folder.', 100); } // get isolated loader require ROOT_LIBRARIES . 'Doctrine/Common/ClassLoader.php'; // setup autoloaders with namespace and path to search in $classLoader = new \Doctrine\Common\ClassLoader('Doctrine', realpath(ROOT_LIBRARIES)); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Symfony', realpath(ROOT_LIBRARIES . 'Doctrine/Symfony')); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Entities', realpath(ROOT . 'doctrine')); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Repositories', realpath(ROOT . 'doctrine')); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Proxies', realpath(ROOT . 'doctrine')); $classLoader->register(); // include Doctrine Extensions $classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', realpath(ROOT_LIBRARIES)); $classLoader->register(); // fetch doctrine config handler for configuring $config = new \Doctrine\ORM\Configuration(); // fetch cache driver - APC in production and Array in development mode if (extension_loaded('apc') and DEBUG == false) { $cache = new \Doctrine\Common\Cache\ApcCache(); } else { $cache = new \Doctrine\Common\Cache\ArrayCache(); } // set cache driver $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); // set annotation driver for entities $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(self::getModelPathsForAllModules())); // @todo workaround till i find a better way to acquire all the models $config->getMetadataDriverImpl()->getAllClassNames(); #Koch_Debug::firebug($config->getMetadataDriverImpl()->getAllClassNames()); // set proxy dirs $config->setProxyDir(realpath(ROOT . 'doctrine')); $config->setProxyNamespace('Proxies'); // regenerate proxies only in debug and not in production mode if (DEBUG == true) { $config->setAutoGenerateProxyClasses(true); } else { $config->setAutoGenerateProxyClasses(false); } // use main configuration values for setting up the connection $connectionOptions = array('driver' => $clansuite_config['database']['driver'], 'user' => $clansuite_config['database']['user'], 'password' => $clansuite_config['database']['password'], 'dbname' => $clansuite_config['database']['dbname'], 'host' => $clansuite_config['database']['host'], 'charset' => $clansuite_config['database']['charset'], 'driverOptions' => array('charset' => $clansuite_config['database']['charset'])); // set up Logger #$config->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger); // we need some more functions for mysql $config->addCustomNumericFunction('RAND', 'DoctrineExtensions\\Query\\Mysql\\Rand'); /** * Events */ $event = new \Doctrine\Common\EventManager(); /** * Database Prefix * * The constant definition is for building (raw) sql queries manually. * The database prefixing is registered via an event. */ define('DB_PREFIX', $clansuite_config['database']['prefix']); $tablePrefix = new \DoctrineExtensions\TablePrefix\TablePrefix(DB_PREFIX); $event->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix); /** * Custom Functions * * We need some more functions for mysql, like RAND for random values. */ $config->addCustomNumericFunction('RAND', 'DoctrineExtensions\\Query\\Mysql\\Rand'); /** * Set UTF-8 handling of database data via Doctrine Event for MySQL. */ if ($clansuite_config['database']['driver'] !== null and $clansuite_config['database']['driver'] == "pdo_mysql") { /** * @todo eval database.charset true? * wouldn't it be better to use utf-8 to name it explicitly */ if ($clansuite_config['database']['charset'] !== null) { $event->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit($clansuite_config['database']['charset'], 'utf8_unicode_ci')); } } // Entity manager $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config, $event); // set DBAL DebugStack Logger (also needed for counting queries) if (defined('DEBUG') and DEBUG == 1) { self::$sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack(); $em->getConfiguration()->setSQLLogger(self::$sqlLoggerStack); /** * Echo SQL Queries directly on the page. */ #$em->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); } self::$em = $em; // done with config, remove to safe memory unset($clansuite_config, $em, $event); return self::$em; }