Пример #1
0
 /**
  * Connect and set-up Doctrine
  *
  * @return void
  */
 public function connect()
 {
     $this->configuration = new \Doctrine\ORM\Configuration();
     // Setup cache
     $this->setDoctrineCache();
     // Set metadata driver
     $chain = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();
     $chain->addDriver($this->createAnnotationDriver(\Includes\Decorator\ADecorator::getCacheModelsDir()), 'XLite\\Model');
     $iterator = new \RecursiveDirectoryIterator(\Includes\Decorator\ADecorator::getCacheClassesDir() . 'XLite' . LC_DS . 'Module', \FilesystemIterator::SKIP_DOTS);
     foreach ($iterator as $dir) {
         if (\Includes\Utils\FileManager::isDir($dir->getPathName())) {
             $iterator2 = new \RecursiveDirectoryIterator($dir->getPathName(), \FilesystemIterator::SKIP_DOTS);
             foreach ($iterator2 as $dir2) {
                 if (\Includes\Utils\FileManager::isDir($dir2->getPathName()) && \Includes\Utils\FileManager::isDir($dir2->getPathName() . LC_DS . 'Model')) {
                     $chain->addDriver($this->createAnnotationDriver($dir2->getPathName() . LC_DS . 'Model'), 'XLite\\Module\\' . $dir->getBaseName() . '\\' . $dir2->getBaseName() . '\\Model');
                 }
             }
         }
     }
     $this->configuration->setMetadataDriverImpl($chain);
     // Set proxy settings
     $this->configuration->setProxyDir(rtrim(\Includes\Decorator\ADecorator::getCacheModelProxiesDir(), LC_DS));
     $this->configuration->setProxyNamespace(LC_MODEL_PROXY_NS);
     $this->configuration->setAutoGenerateProxyClasses(false);
     // Register custom functions
     $this->configuration->addCustomStringFunction('if', '\\XLite\\Core\\Doctrine\\IfFunction');
     $this->configuration->addCustomStringFunction('IFNULL', '\\XLite\\Core\\Doctrine\\IfnullFunction');
     $this->configuration->addCustomStringFunction('relevance', '\\XLite\\Core\\Doctrine\\RelevanceFunction');
     $this->configuration->addCustomNumericFunction('intval', '\\XLite\\Core\\Doctrine\\IntvalFunction');
     $this->configuration->addCustomStringFunction('findInSet', '\\XLite\\Core\\Doctrine\\FindInSetFunction');
     $this->configuration->addCustomStringFunction('castChar', '\\XLite\\Core\\Doctrine\\CastCharFunction');
     $this->configuration->addCustomStringFunction('collate', '\\XLite\\Core\\Doctrine\\CollateFunction');
     $this->tablePrefix = trim(\XLite::getInstance()->getOptions(array('database_details', 'table_prefix')));
     // Initialize DB connection and entity manager
     $this->startEntityManager();
 }