_filesystemName)) { throw new Qs_Db_Exception($this->_errorMap[self::ERROR_FILESYSTEM_NAME_IS_NULL]); } if (empty($this->_baseDirectory)) { throw new Qs_Db_Exception($this->_errorMap[self::ERROR_BASE_DIRECTORY_IS_NULL]); } if (empty($this->_moduleName)) { throw new Qs_Db_Exception($this->_errorMap[self::ERROR_MODULE_NAME_IS_NULL]); } $this->_initProperties(); $codeGenFile = new Zend_CodeGenerator_Php_File(array_merge( array('fileName' => $this->getFullPath()), $this->_getContext() )); $codeGenFile->generate(); return $codeGenFile->write(); } protected function _initProperties() { $this->_classBase = 'App_' . $this->_moduleName . '_'; $this->_fileExtension = strtolower(substr( $this->getFilesystemName(), strrpos($this->getFilesystemName(), '.') + 1)); $this->_classSuffix = ucfirst(strtolower(substr( $this->getFilesystemName(), 0, strrpos($this->getFilesystemName(), '.')))); return $this; } protected function _getContext() { $baseDirectoryNamePart = ''; $baseDirectoryArray = explode(DIRECTORY_SEPARATOR, $this->getBaseDirectory()); if (sizeof($baseDirectoryArray) > App_Admin_Tool_Project_Provider_Module::MODULE_DIRECTORY_LEVEL) { $baseDirectoryNamePart .= implode('', array_slice($baseDirectoryArray, App_Admin_Tool_Project_Provider_Module::MODULE_DIRECTORY_LEVEL)); } $contextClassName = 'App_Admin_Tool_Project_Context_File_' . ucfirst($this->_fileExtension) . '_' . ($this->_fileExtension == self::JS_FILE_EXTENSION ? 'General' : ($baseDirectoryNamePart . $this->_classSuffix)); $options = array( 'moduleName' => $this->_moduleName, // Tool 'classBase' => $this->_classBase, // [App_Admin_]Tool 'classSuffix' => $this->_classSuffix, // App_Admin_[Tool] 'baseDirectory' => $this->getBaseDirectory() // App/Admin or App/Admin/Tool etc. ); $contextClassNameDefault = 'App_Admin_Tool_Project_Context_File_Default_' . ucfirst($this->_fileExtension); /** @var App_Admin_Tool_Project_Context_File_Abstract $contextClassObj */ $contextClassObj = new $contextClassNameDefault($options); $context = $contextClassObj->getContext(); if (class_exists($contextClassName)) { $contextClassObj = new $contextClassName($options); if ($contextClassObj instanceof App_Admin_Tool_Project_Context_File_Abstract && method_exists($contextClassObj, 'getContext') ) { $context = $contextClassObj->getContext(); } } return $context; } /** * @return App_Admin_Tool_Project_Context_BuildFile */ public function delete() { unlink($this->getFullPath()); return $this; } /** * @return bool */ public function exists() { return file_exists($this->getFullPath()); } }