Example #1
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;
 }
Example #2
0
 /**
  * @param Doctrine_Import_Builder $builder
  * @param array $definition
  */
 protected function _buildRecord($builder, $definition)
 {
     $className = $definition['className'];
     if (strpos($className, "Model_") === false) {
         throw ZFDoctrine_DoctrineException::invalidZendModel($className);
     }
     $classPrefix = substr($className, 0, strpos($className, 'Model_') + strlen('Model_'));
     $camelCaseToDash = new Zend_Filter_Word_CamelCaseToDash();
     $moduleName = current(explode("_", $className));
     $moduleName = strtolower($camelCaseToDash->filter($moduleName));
     if (!isset($this->_modules[$moduleName])) {
         throw ZFDoctrine_DoctrineException::unknownModule($moduleName, $className);
     }
     $builder->setTargetPath($this->_modules[$moduleName]);
     $builder->buildRecord($definition);
     if ($this->_listener) {
         $this->_listener->notifyRecordBuilt($className, $moduleName);
     }
 }
Example #3
0
 /**
  * Defined by Zend_Application_Resource_Resource
  *
  * @return  ZFDoctrine_Application_Resource_Doctrine
  * @throws  Zend_Application_Resource_Exception
  */
 public function init()
 {
     if (!class_exists('Doctrine_Core')) {
         throw ZFDoctrine_DoctrineException::doctrineNotFound();
     }
     $manager = $this->_initManager();
     $connections = $this->_initConnections();
     return new ZFDoctrine_Registry($manager, $connections, $this->_paths, $this->_generateModelOptions);
 }