Exemplo n.º 1
0
 public function testLoadModelsZendSingleLibraryStyle()
 {
     $front = Zend_Controller_Front::getInstance();
     $front->addControllerDirectory(dirname(__FILE__) . "/_files/controllers");
     $front->addModuleDirectory(dirname(__FILE__) . "/_files/modules");
     ZFDoctrine_Core::setSingleLibraryPath(dirname(__FILE__) . "/_files/library");
     $directories = ZFDoctrine_Core::getAllModelDirectories();
     $models = ZFDoctrine_Core::loadAllZendModels();
     $this->assertEquals(2, count($models));
     $this->assertContains('Default_Model_Group', $models);
     $this->assertContains('Blog_Model_Category', $models);
 }
Exemplo n.º 2
0
 /**
  * @return void
  */
 protected function _initModules()
 {
     $this->_modules = ZFDoctrine_Core::getAllModelDirectories();
 }
Exemplo n.º 3
0
 protected function _loadDoctrineModels()
 {
     $this->_initDoctrineResource();
     $manager = Doctrine_Manager::getInstance();
     ZFDoctrine_Core::loadModels($this->_getDoctrineRegistry()->getModelPath(), $manager->getAttribute(Doctrine_Core::ATTR_MODEL_LOADING));
 }
Exemplo n.º 4
0
 /**
  * Return module name to module models directory.
  *
  * @return array
  */
 public static function getAllModelDirectories()
 {
     $manager = Doctrine_Manager::getInstance();
     $modelLoading = $manager->getAttribute(Doctrine_Core::ATTR_MODEL_LOADING);
     if (self::$_modelDirs == null) {
         $manager = Doctrine_Manager::getInstance();
         $front = Zend_Controller_Front::getInstance();
         $modules = $front->getControllerDirectory();
         $modelDirectories = array();
         // For all model styles make sure that they end with a / in the directory name!!
         if ($modelLoading == self::MODEL_LOADING_ZEND) {
             $controllerDirName = $front->getModuleControllerDirectoryName();
             foreach ((array) $modules as $module => $controllerDir) {
                 $modelDir = str_replace($controllerDirName, '', $controllerDir) . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR;
                 $modelDirectories[$module] = $modelDir;
             }
         } else {
             if ($modelLoading == self::MODEL_LOADING_ZEND_MODULE_LIBRARY) {
                 $controllerDirName = $front->getModuleControllerDirectoryName();
                 foreach ((array) $modules as $module => $controllerDir) {
                     $modelDir = str_replace($controllerDirName, '', $controllerDir) . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . self::_formatModuleName($module) . DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR;
                     $modelDirectories[$module] = $modelDir;
                 }
             } else {
                 if ($modelLoading == self::MODEL_LOADING_ZEND_SINGLE_LIBRARY) {
                     if (!self::$_singleLibraryPath) {
                         throw ZFDoctrine_DoctrineException::libraryPathMissing();
                     }
                     foreach ((array) $modules as $module => $controllerDir) {
                         $modelDirectories[$module] = self::$_singleLibraryPath . DIRECTORY_SEPARATOR . self::_formatModuleName($module) . DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR;
                     }
                 } else {
                     throw ZFDoctrine_DoctrineException::invalidZendStyle();
                 }
             }
         }
         self::$_modelDirs = $modelDirectories;
     }
     return self::$_modelDirs;
 }