public function factory($table, $module) { $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION); $path = $this->_loadedProfile->getAttribute('projectDirectory'); $dirModules = $path . '/application/configs/modules'; if (!is_dir($dirModules)) { mkdir($dirModules); } $dirModule = $dirModules . '/' . $module; if (!is_dir($dirModule)) { mkdir($dirModule); } $fileName = $dirModule . '/' . $table . '.php'; if (!file_exists($fileName)) { throw new Zend_Tool_Project_Provider_Exception('Para executar essa ação é necessário criar o arquivo ' . $fileName); } $config = (require $fileName); $path .= '/application/modules/' . strtolower($module); /** * Gerando o DataView */ if (!isset($config['table']['modelName'])) { $config['table']['modelName'] = $config['table']['name']; } $modelName = ZendT_Lib::convertTableNameToClassName($config['table']['modelName']); /** * */ if (file_exists($path . '/models/' . $modelName . '/MapperView.php')) { ZendT_Lib::createDirectory($path, '/data-views/' . $modelName . '/Crud'); copy($path . '/models/' . $modelName . '/Crud/MapperView.php', $path . '/data-views/' . $modelName . '/Crud/MapperView.php'); unlink($path . '/models/' . $modelName . '/Crud/MapperView.php'); $content = file_get_contents($path . '/data-views/' . $modelName . '/Crud/MapperView.php'); $content = str_replace(ucfirst($module) . '_Model_' . $modelName . '_Crud_MapperView', ucfirst($module) . '_DataView_' . $modelName . '_Crud_MapperView', $content); file_put_contents($path . '/data-views/' . $modelName . '/Crud/MapperView.php', $content); copy($path . '/models/' . $modelName . '/MapperView.php', $path . '/data-views/' . $modelName . '/MapperView.php'); unlink($path . '/models/' . $modelName . '/MapperView.php'); $content = file_get_contents($path . '/data-views/' . $modelName . '/MapperView.php'); $content = str_replace(ucfirst($module) . '_Model_' . $modelName . '_MapperView', ucfirst($module) . '_DataView_' . $modelName . '_MapperView', $content); $content = str_replace(ucfirst($module) . '_Model_' . $modelName . '_Crud_MapperView', ucfirst($module) . '_DataView_' . $modelName . '_Crud_MapperView', $content); file_put_contents($path . '/data-views/' . $modelName . '/MapperView.php', $content); $content = file_get_contents($path . '/controllers/' . $modelName . 'Controller.php'); $content = str_replace(ucfirst($module) . '_Model_' . $modelName . '_MapperView', ucfirst($module) . '_DataView_' . $modelName . '_MapperView', $content); file_put_contents($path . '/controllers/' . $modelName . 'Controller.php', $content); $this->_print('Objeto MapperView fatorado com sucesso!'); } else { $this->_print('Objeto MapperView já fatorado'); } /** * */ if (file_exists($path . '/models/' . $modelName . '/Element.php')) { copy($path . '/models/' . $modelName . '/Crud/Element.php', $path . '/forms/' . $modelName . '/Crud/Elements.php'); unlink($path . '/models/' . $modelName . '/Crud/Element.php'); $content = file_get_contents($path . '/forms/' . $modelName . '/Crud/Elements.php'); $content = str_replace(ucfirst($module) . '_Model_' . $modelName . '_Crud_Element', ucfirst($module) . '_Form_' . $modelName . '_Crud_Elements', $content); file_put_contents($path . '/forms/' . $modelName . '/Crud/Elements.php', $content); copy($path . '/models/' . $modelName . '/Element.php', $path . '/forms/' . $modelName . '/Elements.php'); unlink($path . '/models/' . $modelName . '/Element.php'); $content = file_get_contents($path . '/forms/' . $modelName . '/Elements.php'); $content = str_replace(ucfirst($module) . '_Model_' . $modelName . '_Element', ucfirst($module) . '_Form_' . $modelName . '_Elements', $content); $content = str_replace(ucfirst($module) . '_Model_' . $modelName . '_Crud_Element', ucfirst($module) . '_Form_' . $modelName . '_Crud_Elements', $content); file_put_contents($path . '/forms/' . $modelName . '/Elements.php', $content); $this->_print('Objeto Element fatorado com sucesso!'); } else { $this->_print('Objeto Element já fatorado'); } ZendT_Lib::replaceFiles($path, ucfirst($module) . '_Model_' . $modelName . '_MapperView', ucfirst($module) . '_DataView_' . $modelName . '_MapperView'); ZendT_Lib::replaceFiles($path, ucfirst($module) . '_Model_' . $modelName . '_Element', ucfirst($module) . '_Form_' . $modelName . '_Elements'); $path = $this->_loadedProfile->getAttribute('projectDirectory'); $this->_print(' Criando Tables '); ZendT_Tool_Crud_Table::create($path, $config); $this->_print(' Criando Mappers '); ZendT_Tool_Crud_Mapper::create($path, $config); $this->_print(' Criando MapperView '); ZendT_Tool_Crud_MapperView::create($path, $config); $this->_print(' Criando Elements '); ZendT_Tool_Crud_Element::create($path, $config); $this->_print(' Criando Form '); ZendT_Tool_Crud_Form::create($path, $config); $this->_print(' Criando Bootstrap '); ZendT_Tool_Crud_Bootstrap::create($path, $config, 1); $this->_print('Finalizado Factory ' . $table); }
public static function replaceFiles($pathBase, $strOld, $strNew, $filter = '*.*') { $pathBase = str_replace('\\', '/', $pathBase); $files = glob($pathBase . '/' . $filter); foreach ($files as $file) { file_put_contents($file, str_replace($strOld, $strNew, file_get_contents($file))); } @($myDirectory = opendir($pathBase)); if ($myDirectory) { while ($dir = @readdir($myDirectory)) { if ($dir != '.' && $dir != '..' && $dir != '.svn' && is_dir($pathBase . '/' . $dir)) { ZendT_Lib::replaceFiles($pathBase . '/' . $dir, $strOld, $strNew, $filter); } } closedir($myDirectory); } }