/** * Set config value * * @param string $path separated by slash (/) * @param string $value */ public function set($path, $value) { $segments = explode('/', $path); $node = $this->_xml; foreach ($segments as $_key => $_segment) { if (!$node->{$_segment}->getName()) { $node->addChild($_segment); } if ($_key == count($segments) - 1) { $node->{$_segment} = $value; } $node = $node->{$_segment}; } Mtool_Codegen_Filesystem::write($this->_path, $this->asPrettyXML()); }
/** * Get parsed template content * @return string */ public function content() { $templatePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Template' . DIRECTORY_SEPARATOR . "{$this->_template}.tpl"; $source = Mtool_Codegen_Filesystem::read($templatePath); return $this->parse($source); }
/** * Get project root directory path * * @return string */ public static function getRoot() { return rtrim(Mtool_Codegen_Filesystem::slash(getcwd()), '/'); }
/** * Check if module exists * @return boolean */ public function exists() { // Decide by existance of config.xml file return Mtool_Codegen_Filesystem::exists($this->_moduleConfigsDir . DIRECTORY_SEPARATOR . 'config.xml'); }
/** * Create class file * * @param string $path in format: class_path_string * @param string $template * @param Mtool_Codegen_Entity_Module $module * @param array $params * @return resulting class name */ public function createClass($path, $template, $module, $params = array()) { $pathSteps = $this->_ucPath(explode('_', $path)); $className = implode('_', $pathSteps); $classFilename = array_pop($pathSteps) . '.php'; // Create class dir under module $classDir = Mtool_Codegen_Filesystem::slash($module->getDir()) . $this->_folderName . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $pathSteps); Mtool_Codegen_Filesystem::mkdir($classDir); // Move class template file $classTemplate = new Mtool_Codegen_Template($template); $resultingClassName = "{$module->getName()}_{$this->_entityName}_{$className}"; if (strlen('class ' . $resultingClassName) >= self::RECOMMENDED_ZEND_CODING_STANDARD_LINE_LENGTH) { $resultingClassName .= "\n "; } $defaultParams = array('company_name' => $module->getCompanyName(), 'module_name' => $module->getModuleName(), 'class_name' => $resultingClassName, 'year' => date('Y')); $classTemplate->setParams(array_merge($defaultParams, $params, $module->getTemplateParams())); $classTemplate->move($classDir, $classFilename); return $resultingClassName; }