示例#1
0
 protected function _initDoctrine()
 {
     require_once LIBRARY_PATH . '/Doctrine/Common/ClassLoader.php';
     $autoloader = \Zend_Loader_Autoloader::getInstance();
     $fmmAutoloader = new \Doctrine\Common\ClassLoader();
     $autoloader->pushAutoloader(array($fmmAutoloader, 'loadClass'));
     $options = $this->getOptions();
     $config = new Doctrine\ORM\Configuration();
     $config->addCustomDatetimeFunction('YEAR', 'Doctrine\\Extensions\\Query\\Mysql\\Year');
     $config->addCustomDatetimeFunction('MONTH', 'Doctrine\\Extensions\\Query\\Mysql\\Month');
     $config->addCustomDatetimeFunction('DAY', 'Doctrine\\Extensions\\Query\\Mysql\\Day');
     $config->addCustomStringFunction('DATEDIFF', 'Doctrine\\Extensions\\Query\\Mysql\\DateDiff');
     $config->addCustomStringFunction('DATE_FORMAT', 'Doctrine\\Extensions\\Query\\Mysql\\DateFormat');
     $config->addCustomStringFunction('IF', 'Doctrine\\Extensions\\Query\\Mysql\\IfElse');
     $config->addCustomStringFunction('GROUP_CONCAT', 'Doctrine\\Extensions\\Query\\Mysql\\GroupConcat');
     $config->addCustomStringFunction('IFNULL', 'Doctrine\\Extensions\\Query\\Mysql\\IfNull');
     $config->setProxyDir($options['doctrine']['metadata']['proxyDir']);
     $config->setProxyNamespace('Doctrine\\Proxy');
     $config->setAutoGenerateProxyClasses(true);
     $config->setAutoGenerateProxyClasses(APPLICATION_ENV == 'development');
     //$driverImpl = $config->newDefaultAnnotationDriver($options['metadata']['entityDir']);
     $driverImpl = new Doctrine\ORM\Mapping\Driver\YamlDriver($options['doctrine']['metadata']['entityDir']);
     $config->setMetadataDriverImpl($driverImpl);
     $cache = new Doctrine\Common\Cache\ArrayCache();
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     $evm = new Doctrine\Common\EventManager();
     $em = Doctrine\ORM\EntityManager::create($options['doctrine']['db'], $config, $evm);
     Zend_Registry::set('doctrine', $em);
     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('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;
 }
示例#5
0
 private static function newConnect()
 {
     $dir = __DIR__ . '/../../libs/Doctrine/';
     $vendorPath = realpath($dir);
     $ExtensionPath = realpath($dir . '/DoctrineExtensions');
     require_once $vendorPath . '/Doctrine/Common/ClassLoader.php';
     // autoload all vendors
     $loader = new Doctrine\Common\ClassLoader('Doctrine\\Common', $vendorPath);
     $loader->register();
     $loader = new Doctrine\Common\ClassLoader('Doctrine\\DBAL', $vendorPath);
     $loader->register();
     $loader = new Doctrine\Common\ClassLoader('Doctrine\\ORM', $vendorPath);
     $loader->register();
     // gedmo extensions
     $loader = new Doctrine\Common\ClassLoader('Gedmo', $ExtensionPath);
     $loader->register();
     // Pagefanta
     $classLoader = new Doctrine\Common\ClassLoader("Pagerfanta", $ExtensionPath);
     $classLoader->register();
     //MYSQL Functions
     $classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', realpath($dir));
     $classLoader->register();
     // autoloader for Entity namespace
     $loader = new Doctrine\Common\ClassLoader('Entities', $dir);
     $loader->register();
     // ensure standard doctrine annotations are registered
     Doctrine\Common\Annotations\AnnotationRegistry::registerFile($vendorPath . '/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
     // Second configure ORM
     // globally used cache driver
     $cache = new Doctrine\Common\Cache\ArrayCache();
     $reader = new \Doctrine\Common\Annotations\AnnotationReader();
     Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace('Gedmo\\Mapping\\Annotation', $ExtensionPath);
     $driverChain = new \Doctrine\ORM\Mapping\Driver\DriverChain();
     $annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, array($dir . 'Entities', $ExtensionPath . '/Gedmo/Tree/Entity'));
     // drivers
     $driverChain->addDriver($annotationDriver, 'Gedmo\\Tree\\Entity');
     $driverChain->addDriver($annotationDriver, 'Entities');
     // general ORM configuration
     $config = new Doctrine\ORM\Configuration();
     //$config->setProxyDir(sys_get_temp_dir());
     $config->setProxyDir($dir . '/Proxies');
     $config->setProxyNamespace('Proxy');
     $config->setAutoGenerateProxyClasses(true);
     // this can be based on production config. FALSE
     // register metadata driver
     $config->setMetadataDriverImpl($driverChain);
     // use our allready initialized cache driver
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     // Third, create event manager and hook prefered extension listeners
     $evm = new Doctrine\Common\EventManager();
     // gedmo extension listeners
     // tree
     $treeListener = new Gedmo\Tree\TreeListener();
     $treeListener->setAnnotationReader($reader);
     $evm->addEventSubscriber($treeListener);
     // timestampable
     $timestampableListener = new Gedmo\Timestampable\TimestampableListener();
     $timestampableListener->setAnnotationReader($reader);
     $evm->addEventSubscriber($timestampableListener);
     // mysql set names UTF-8 if required
     $evm->addEventSubscriber(new Doctrine\DBAL\Event\Listeners\MysqlSessionInit());
     // Finally, create entity manager
     $connection = array('dbname' => DB_DATABASE, 'user' => DB_USER, 'password' => DB_PASSWORD, 'host' => DB_HOST, 'driver' => 'pdo_mysql');
     $config->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\\Query\\Mysql\\Year');
     $config->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\\Query\\Mysql\\Month');
     $config->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\\Query\\Mysql\\Day');
     $config->addCustomDatetimeFunction('HOUR', 'DoctrineExtensions\\Query\\Mysql\\Hour');
     $config->addCustomDatetimeFunction('DATE', 'DoctrineExtensions\\Query\\Mysql\\Date');
     $config->addCustomDatetimeFunction('DATEDIFF', 'DoctrineExtensions\\Query\\MySql\\DateDiff');
     try {
         $em = Doctrine\ORM\EntityManager::create($connection, $config, $evm);
     } catch (Exception $e) {
     }
     self::$EntityManager = $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\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;
 }
 /**
  * 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 = $this->get('annotation_reader');
     $b = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($a, array(0 => $this->targetDirs[3] . '/vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity', 1 => $this->targetDirs[3] . '/src/Proshut/UserBundle/Entity', 2 => $this->targetDirs[3] . '/src/Proshut/LanguageBundle/Entity', 3 => $this->targetDirs[3] . '/src/Proshut/AttachmentBundle/Entity', 4 => $this->targetDirs[3] . '/src/Proshut/ArticleBundle/Entity'));
     $c = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();
     $c->addDriver($b, 'Gedmo\\Tree\\Entity');
     $c->addDriver($b, 'Proshut\\UserBundle\\Entity');
     $c->addDriver($b, 'Proshut\\LanguageBundle\\Entity');
     $c->addDriver($b, 'Proshut\\AttachmentBundle\\Entity');
     $c->addDriver($b, 'Proshut\\ArticleBundle\\Entity');
     $d = new \Doctrine\ORM\Configuration();
     $d->setEntityNamespaces(array('Gedmo' => 'Gedmo\\Tree\\Entity', 'ProshutUserBundle' => 'Proshut\\UserBundle\\Entity', 'ProshutLanguageBundle' => 'Proshut\\LanguageBundle\\Entity', 'ProshutAttachmentBundle' => 'Proshut\\AttachmentBundle\\Entity', 'ProshutArticleBundle' => 'Proshut\\ArticleBundle\\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->addCustomDatetimeFunction('date', 'Proshut\\AttachmentBundle\\DQL\\DateFunction');
     $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;
 }