_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(); $path = dirname($this->getFullPath()); mkdir($path, 0777, true); file_put_contents($this->getFullPath(), $this->_getContext()); return true; } protected function _initProperties() { $this->_classBase = 'App_' . $this->_moduleName . '_'; $this->_fileExtension = substr($this->getFilesystemName(), strrpos($this->getFilesystemName(), '.') + 1); $this->_fileExtension = strtolower($this->_fileExtension); $this->_classSuffix = substr($this->getFilesystemName(), 0, strrpos($this->getFilesystemName(), '.')); $this->_classSuffix = ucfirst($this->_classSuffix); return $this; } protected function _getContext() { $baseDirectoryNamePart = ''; $baseDirectoryArray = explode(DIRECTORY_SEPARATOR, $this->getBaseDirectory()); $startPosition = null; foreach ($baseDirectoryArray as $key => $item) { if ($item == App_Admin_Tool_Project_Provider_Module::ADMIN_DIRECTORY_NAME || $item == App_Admin_Tool_Project_Provider_Module::ABSTRACT_DIRECTORY_NAME ) { $startPosition = $key; } } if ($startPosition) { $baseDirectoryNamePart .= implode('', array_slice($baseDirectoryArray, $startPosition)); } if ($this->_useNamespace && $this->_classSuffix == $this->_moduleName . 'List') { $this->_classSuffix = 'ModuleNameList'; } $contextClassName = $this->_fileExtension == self::JS_FILE_EXTENSION ? 'General' : ($baseDirectoryNamePart . $this->_classSuffix); $contextClassName = 'App_Admin_Tool_Project_Context_File_' . ucfirst($this->_fileExtension) . '_' . $contextClassName; $options = [ '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. 'params' => $this->_params, ]; $contextClassNameDefault = 'App_Admin_Tool_Project_Context_File_Default_' . ucfirst($this->_fileExtension); /** @var App_Admin_Tool_Project_Context_File_Abstract $contextClassObj */ $contextClassObj = new $contextClassNameDefault($options); $contextClassObj->setUseNamespace($this->_useNamespace); $context = $contextClassObj->getContext(); if (class_exists($contextClassName)) { $contextClassObj = new $contextClassName($options); $contextClassObj->setUseNamespace($this->_useNamespace); 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()); } public function setUseNamespace($useNamespace) { $this->_useNamespace = $useNamespace; } }