* @access public
* @param string $basedir ベースディレクトリ
* @param array $types プラグインのtype (Validator, Handle等)
- * @param string $no_ini iniファイル生成フラグ
+ * @param string $forpackage iniファイル生成フラグ
* @param string $plugin_name プラグイン名
* @return true|Ethna_Error true:成功 Ethna_Error:失敗
*/
- function &generate($basedir, $types = array(), $no_ini = false, $plugin_name)
+ function &generate($basedir, $types = array(), $forpackage = false, $plugin_name)
{
- // create plugin directory
$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);
- } else {
- printf("directory [$plugin_dir] already exists -> skip.\n");
}
+
// type check.
if (empty($types)) {
return Ethna::raiseError('please specify plugin type.');
}
- // generate ini file
- if ($no_ini == false) {
- $ini_skel = 'plugin/skel.plugin.ini';
- $ini_file = strtolower($plugin_name) . '.ini';
- $ini_path = "$plugin_dir/$ini_file";
-
- $macro['plugin_name'] = $plugin_name;
- 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);
+ //
+ // 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');
}
}
//
$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;
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";
}
}
+ // 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;
}
array(
'basedir=',
'type=',
- 'noini',
+ 'no-inifile',
+ 'plugin-package',
)
);
if (Ethna::isError($r)) {
}
// no-ini file flag.
- $no_ini = (isset($opt_list['noini'])) ? true : false;
+ $forpackage = (isset($opt_list['plugin-package'])) ? true : false;
- $r = Ethna_Generator::generate('CreatePlugin', NULL, $basedir, $types, $no_ini, $plugin_name);
+ $r = Ethna_Generator::generate('CreatePlugin', NULL, $basedir, $types, $forpackage, $plugin_name);
if (Ethna::isError($r)) {
printf("error occurred while generating plugin skelton. please see also error messages given above\n\n");
return $r;
}
- printf("\nplugin skelton for [%s] is successfully generated at [%s]\n\n", $plugin_name, "$basedir/$plugin_name");
+ printf("\nplugin skelton for [%s] is successfully generated.\n\n", $plugin_name);
return true;
}
// }}}
function getUsage()
{
return <<<EOS
-ethna {$this->id} [-b|--basedir=dir] [-t|--type=f,v,sb,sf,sm...] [-n|--no-inifile] plugin-name
- type is as follows (separated by comma):
+ethna {$this->id} [-b|--basedir=dir] [-t|--type=f,v,sb,sf,sm...] [-p|--plugin-package] plugin-name
+ -t: type is as follows (separated by comma):
f = Filter (default),
v = Validator (default),
sm = Smarty modifier (default)
sb = Smarty block,
sf = Smarty function,
+ -p: if you want to make plugin package, set this option.
EOS;
}
// }}}
{
return <<<EOS
make plugin package:
- {$this->id} [-b|--basedir=dir] [-t|--type=f,v,sb,sf,sm...] [-n|--no-inifile] plugin-name
+ {$this->id} [-b|--basedir=dir] [-t|--type=f,v,sb,sf,sm...] [-p|--plugin-package] plugin-name
EOS;
}
// }}}