/** * スケルトンを削除する * * @access public * @param string $type 生成する対象 * @param string $app_dir アプリケーションのディレクトリ * (nullのときはアプリケーションを特定しない) * @param mixed residue プラグインのremove()にそのまま渡す * @static */ function &remove() { $arg_list = func_get_args(); $type = array_shift($arg_list); $app_dir = array_shift($arg_list); if ($app_dir === null) { $ctl =& Ethna_Handle::getEthnaController(); } else { $ctl =& Ethna_Handle::getAppController($app_dir); } if (Ethna::isError($ctl)) { return $ctl; } $plugin_manager =& $ctl->getPlugin(); if (Ethna::isError($plugin_manager)) { return $plugin_manager; } $generator =& $plugin_manager->getPlugin('Generator', $type); if (Ethna::isError($generator)) { return $generator; } // 引数はプラグイン依存とする $ret = call_user_func_array(array(&$generator, 'remove'), $arg_list); return $ret; }
/** * Special Function for generating template. * * @param string $target_name Template Name * @param array $opt_list Option List. * @access protected */ function _performTemplate($target_name, $opt_list) { // basedir if (isset($opt_list['basedir'])) { $basedir = realpath(end($opt_list['basedir'])); } else { $basedir = getcwd(); } // skelfile if (isset($opt_list['skelfile'])) { $skelfile = end($opt_list['skelfile']); } else { $skelfile = null; } // locale $ctl = Ethna_Handle::getAppController(getcwd()); if (isset($opt_list['locale'])) { $locale = end($opt_list['locale']); if (!preg_match('/^[A-Za-z_]+$/', $locale)) { return Ethna::raiseError("You specified locale, but invalid : {$locale}", 'usage'); } } else { if (Ethna::isError($ctl)) { $locale = 'ja_JP'; } else { $locale = $ctl->getLocale(); } } // encoding if (isset($opt_list['encoding'])) { $encoding = end($opt_list['encoding']); if (function_exists('mb_list_encodings')) { $supported_enc = mb_list_encodings(); if (!in_array($encoding, $supported_enc)) { return Ethna::raiseError("Unknown Encoding : {$encoding}", 'usage'); } } } else { if (Ethna::isError($ctl)) { $encoding = 'UTF-8'; } else { $encoding = $ctl->getClientEncoding(); } } $r = Ethna_Generator::generate('Template', $basedir, $target_name, $skelfile, $locale, $encoding); if (Ethna::isError($r)) { printf("error occurred while generating skelton. please see also following error message(s)\n\n"); return $r; } $true = true; return $true; }
protected function configure() { $this->setName($this->controller); $this->ignoreValidationErrors(); $controller = \Ethna_Handle::getAppController(getcwd()); $action_name = $this->action_name; $controller->setActionCli($action_name); $controller->setActionName($controller->executePreActionFilter($action_name)); $controller->setupActionForm($action_name); foreach ($controller->getBackend()->getActionForm()->getDef() as $key => $definition) { $this->addOption($key, null, InputOption::VALUE_REQUIRED); } }
/** * clear cache files. * * @access public * @todo implement Ethna_Renderer::clear_cache(); * @todo implement Ethna_Plugin_Cachemanager::clear_cache(); * @todo avoid echo, printf */ function perform() { $r = $this->_getopt(array('basedir=', 'any-tmp-files', 'smarty', 'pear', 'cachemanager')); if (Ethna::isError($r)) { return $r; } list($args, ) = $r; $basedir = isset($args['basedir']) ? realpath(end($args['basedir'])) : getcwd(); $controller = Ethna_Handle::getAppController($basedir); if (Ethna::isError($controller)) { return $controller; } $tmp_dir = $controller->getDirectory('tmp'); if (isset($args['smarty']) || isset($args['any-tmp-files'])) { echo "cleaning smarty caches, compiled templates..."; $renderer = $controller->getRenderer(); if (strtolower(get_class($renderer)) == "ethna_renderer_smarty") { $renderer->getEngine()->clear_all_cache(); $renderer->getEngine()->clear_compiled_tpl(); } echo " done\n"; } if (isset($args['cachemanager']) || isset($args['any-tmp-files'])) { echo "cleaning Ethna_Plugin_Cachemanager caches..."; $cache_dir = sprintf("%s/cache", $tmp_dir); Ethna_Util::purgeDir($cache_dir); echo " done\n"; } if (isset($args['any-tmp-files'])) { echo "cleaning tmp dirs..."; // purge only entries in tmp. if ($dh = opendir($tmp_dir)) { while (($entry = readdir($dh)) !== false) { if ($entry === '.' || $entry === '..') { continue; } Ethna_Util::purgeDir("{$tmp_dir}/{$entry}"); } closedir($dh); } echo " done\n"; } return true; }
ob_end_clean(); } $base = dirname(dirname(dirname(__FILE__))); ini_set('include_path', $base . PATH_SEPARATOR . ini_get('include_path')); require_once 'Ethna/Ethna.php'; require_once ETHNA_BASE . '/class/Getopt.php'; // fetch arguments $opt = new Ethna_Getopt(); $arg_list = $opt->readPHPArgv(); if (Ethna::isError($arg_list)) { echo $arg_list->getMessage() . "\n"; exit(2); } array_shift($arg_list); // remove "ethna_handle.php" $eh = new Ethna_Handle(); // はじめの引数に - が含まれていればそれを分離する // 含まれていた場合、それは -v|--version でなければならない list($my_arg_list, $arg_list) = _Ethna_HandleGateway_SeparateArgList($arg_list); $r = $opt->getopt($my_arg_list, "v", array("version")); if (Ethna::isError($r)) { $id = 'help'; } else { // ad-hoc:( foreach ($r[0] as $opt) { if ($opt[0] == "v" || $opt[0] == "--version") { _Ethna_HandleGateway_ShowVersion(); exit(2); } } }
/** * setup PEAR_Config and so on. * * @param string $target whether 'master' or 'local' * @param string|null $app_dir local application directory. * @param string|null $channel channel for the package repository. * @return true|Ethna_Error */ public function init($target, $app_dir = null, $channel = null) { $true = true; if ($target == 'master') { $this->target = 'master'; } else { // default target is 'local'. $this->target = 'local'; } // setup PEAR_Frontend PEAR_Command::setFrontendType('CLI'); $this->ui = PEAR_Command::getFrontendObject(); // set PEAR's error handling // TODO: if PEAR/Command/Install.php is newer than 1.117, displayError goes well. PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(&$this->ui, 'displayFatalError')); // set channel $master_setting = Ethna_Handle::getMasterSetting('repositry'); if ($channel !== null) { $this->channel = $channel; } else { if (isset($master_setting["channel_{$target}"])) { $this->channel = $master_setting["channel_{$target}"]; } else { $this->channel = 'pear.ethna.jp'; } } // set target controller if ($target == 'master') { $this->target_ctl = Ethna_Handle::getEthnaController(); } else { $this->target_ctl = Ethna_Handle::getAppController($app_dir); } if (Ethna::isError($this->target_ctl)) { return $this->target_ctl; } // setup PEAR_Config if ($target == 'master') { $ret = $this->_setMasterConfig(); } else { $ret = $this->_setLocalConfig(); } if (Ethna::isError($ret)) { return $ret; } $this->ui->setConfig($this->config); // setup PEAR_Registry $this->registry = $this->config->getRegistry(); return $true; }
/** * テンプレートのスケルトンを生成する * * @access public * @param string $basedir ベースディレクトリ * @param array $types プラグインのtype (Validator, Handle等) * @param string $forpackage iniファイル生成フラグ * @param string $plugin_name プラグイン名 * @return true|Ethna_Error true:成功 Ethna_Error:失敗 */ function generate($basedir, $types = array(), $forpackage = false, $plugin_name) { $plugin_dir = "{$basedir}/plugin"; if (!$forpackage) { $chk_ctl = Ethna_Handle::getAppController(getcwd()); if (Ethna::isError($chk_ctl)) { return Ethna::raiseError("ERROR: You are not in Ethna project. specify [-p|--plugin-package] option, or change directory to the Ethna Project\n"); } $plugin_dir = $chk_ctl->getDirectory('plugin'); } // create plugin directory if (!file_exists($plugin_dir)) { Ethna_Util::mkdir($plugin_dir, 0755); } // type check. if (empty($types)) { return Ethna::raiseError('please specify plugin type.'); } // // type check // foreach ($types as $type) { switch (strtolower($type)) { case 'f': case 'v': case 'sm': case 'sb': case 'sf': break; default: return Ethna::raiseError("unknown plugin type: {$type}", 'usage'); } } // // Generate Plugin PHP File // $plugin_name = ucfirst(strtolower($plugin_name)); $lplugin_name = strtolower($plugin_name); $macro['plugin_name'] = $plugin_name; foreach ($types as $type) { $ltype = strtolower($type); $macro['plugin_type'] = $type; $plugin_file_skel = "plugin/skel.plugin.{$ltype}.php"; // create directory switch ($type) { case 'f': $type = 'Filter'; $pfilename = "{$plugin_name}.php"; break; case 'v': $type = 'Validator'; $pfilename = "{$plugin_name}.php"; break; case 'sm': $type = 'Smarty'; $pfilename = "modifier.{$lplugin_name}.php"; $macro['plugin_name'] = $lplugin_name; break; case 'sb': $type = 'Smarty'; $pfilename = "block.{$lplugin_name}.php"; $macro['plugin_name'] = $lplugin_name; break; case 'sf': $type = 'Smarty'; $pfilename = "function.{$lplugin_name}.php"; $macro['plugin_name'] = $lplugin_name; break; } $type_dir = "{$plugin_dir}/{$type}"; if (!file_exists($type_dir)) { Ethna_Util::mkdir($type_dir, 0755); } $type_file_path = "{$type_dir}/{$pfilename}"; // generate if (file_exists($type_file_path)) { printf("file [%s] already exists -> skip\n", $type_file_path); } else { if ($this->_generateFile($plugin_file_skel, $type_file_path, $macro) == false) { printf("[warning] file creation failed [%s]\n", $type_file_path); } else { printf("plugin php file successfully created [%s]\n", $type_file_path); } } } // generate ini file if ($forpackage) { $ini_skel = 'plugin/skel.plugin.ini'; $ini_file = strtolower($plugin_name) . '.ini'; $ini_path = "{$plugin_dir}/{$ini_file}"; if (file_exists($ini_path)) { printf("file [%s] already exists -> skip\n", $ini_file); } else { if ($this->_generateFile($ini_skel, $ini_path, $macro) == false) { printf("[warning] file creation failed [%s]\n", $ini_file); } else { printf("plugin ini file successfully created [%s]\n", $ini_file); } } } $true = true; return $true; }
function &getController() { if (($r = $this->create_ifnot_exists()) !== true) { return $r; } $ctl = Ethna_Handle::getAppController($this->proj_basedir); // キャッシュが返されるため、$GLOBALSが設定されない場合がある $GLOBALS['_Ethna_controller'] = $ctl; return $ctl; }
/** * コマンドの実装 * * @access public * @return mixed 成否結果(true=>成功, Ethna_Error=>失敗) */ function &perform() { // 引数取得 $r = $this->_getopt(array("basedir=", "overwrite=", "skelton-namespace=")); if (Ethna::isError($r)) { return $r; } list($optlist, $arglist) = $r; $r =& Ethna_Controller::checkActionName($arglist[0]); if (Ethna::isError($r)) { return $r; } // 引数処理 $app_dir = isset($optlist['basedir']) ? $optlist['basedir'] : getcwd(); $baseAction = $arglist[0]; $model = $arglist[1]; // アプリケーションController取得 $c =& Ethna_Handle::getAppController($app_dir); if (Ethna::isError($c)) { echo 'Not found Project Directory!'; return $c; } // Backend取得 $backend =& $c->getBackend(); $generator =& new Ethna_Generator(); // Template AppObject生成 $r =& $generator->generate('ScaffoldTemplateAppObject', $app_dir); if (Ethna::isError($r)) { return $r; } // AppObject生成 $r =& $generator->generate('ScaffoldAppObject', $app_dir, $model); if (Ethna::isError($r)) { return $r; } // AppObject取得 $appObj =& $backend->getObject($model); $modelDefine = $appObj->prop_def; $idDefine = $appObj->getIdDef(); // ActionForm定義 $formDefine = $this->_getActionFormDefine($model, $modelDefine); // カラム名定義 $r =& $generator->generate('ScaffoldColumnName', $app_dir, $model, $modelDefine); if (Ethna::isError($r)) { return $r; } // BaseActionForm Generator $r =& $generator->generate('ScaffoldActionForm', $app_dir, $model, $modelDefine, $formDefine); if (Ethna::isError($r)) { return $r; } // Actions Generator $r =& $generator->generate('ScaffoldActions', $app_dir, $baseAction, $model, $modelDefine, $idDefine, $formDefine); if (Ethna::isError($r)) { return $r; } // Views Generator $r =& $generator->generate('ScaffoldViews', $app_dir, $baseAction, $model, $modelDefine, $idDefine, $formDefine); if (Ethna::isError($r)) { return $r; } // Templates Generator $r =& $generator->generate('ScaffoldTemplates', $app_dir, $baseAction, $model, $modelDefine, $idDefine, $formDefine); if (Ethna::isError($r)) { return $r; } // Smarty Plugin $r =& $generator->generate('ScaffoldSmartyPlugin', $app_dir); if (Ethna::isError($r)) { return $r; } // UnitTestCase Generator // UnitTestCase GeneratorはEthcaffoldの標準に含まれているものではないため無い場合がある $r =& $generator->generate('UnitTestCase', $app_dir, $model); if (Ethna::isError($r)) { if ($r->getCode() !== E_PLUGIN_NOTFOUND) { return $r; } } $true = true; return $true; }