2 // vim: foldmethod=marker
6 * @author Masaki Fujimoto <fujimoto@php.net>
7 * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
12 // {{{ Ethna_Plugin_Handle_AddProject
16 * @author Masaki Fujimoto <fujimoto@php.net>
20 class Ethna_Plugin_Handle_AddProject extends Ethna_Plugin_Handle
29 $r = $this->_getopt(array('basedir=', 'skeldir=', 'locale=', 'encoding='));
30 if (Ethna::isError($r)) {
33 list($opt_list, $arg_list) = $r;
36 $app_id = array_shift($arg_list);
37 if ($app_id == null) {
38 return Ethna::raiseError('Application id isn\'t set.', 'usage');
40 $r = Ethna_Controller::checkAppId($app_id);
41 if (Ethna::isError($r)) {
46 if (isset($opt_list['basedir'])) {
47 $dir = end($opt_list['basedir']);
48 $basedir = realpath($dir);
49 if ($basedir === false) { // e.x file does not exist
53 $basedir = sprintf("%s/%s", getcwd(), strtolower($app_id));
57 if (isset($opt_list['skeldir'])) {
58 $selected_dir = end($opt_list['skeldir']);
59 $skeldir = realpath($selected_dir);
60 if ($skeldir == false || is_dir($skeldir) == false || file_exists($skeldir) == false) {
61 return Ethna::raiseError("You specified skeldir, but invalid : $selected_dir", 'usage');
68 if (isset($opt_list['locale'])) {
69 $locale = end($opt_list['locale']);
70 if (!preg_match('/^[A-Za-z_]+$/', $locale)) {
71 return Ethna::raiseError("You specified locale, but invalid : $locale", 'usage');
74 $locale = 'ja_JP'; // default locale.
78 if (isset($opt_list['encoding'])) {
79 $encoding = end($opt_list['encoding']);
80 if (function_exists('mb_list_encodings')) {
81 $supported_enc = mb_list_encodings();
82 if (!in_array($encoding, $supported_enc)) {
83 return Ethna::raiseError("Unknown Encoding : $encoding", 'usage');
87 $encoding = 'UTF-8'; // default encoding.
90 $r = Ethna_Generator::generate('Project', null, $app_id, $basedir, $skeldir, $locale, $encoding);
91 if (Ethna::isError($r)) {
92 printf("error occurred while generating skelton. please see also error messages given above\n\n");
96 printf("\nproject skelton for [%s] is successfully generated at [%s]\n\n", $app_id, $basedir);
101 * get handler's description
105 function getDescription()
109 {$this->id} [-b|--basedir=dir] [-s|--skeldir] [-l|--locale] [-e|--encoding] [Application id]
122 ethna {$this->id} [-b|--basedir=dir] [-s|--skeldir] [-l|--locale] [-e|--encoding] [Application id]