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 require_once 'Ethna/class/Plugin/Handle/AddAction.php';
14 // {{{ Ethna_Plugin_Handle_AddView
18 * @author Masaki Fujimoto <fujimoto@php.net>
22 class Ethna_Plugin_Handle_AddView extends Ethna_Plugin_Handle_AddAction
32 // '-w[with-unittest]' and '-u[unittestskel]' option
33 // are not intuisive, but I dare to define them because
34 // -t and -s option are reserved by add-[action|view] handle
35 // and Ethna_Getopt cannot interpret two-character option.
47 if (Ethna::isError($r)) {
50 list($opt_list, $arg_list) = $r;
53 $view_name = array_shift($arg_list);
54 if ($view_name == null) {
55 return Ethna::raiseError('view name isn\'t set.', 'usage');
57 $r =& Ethna_Controller::checkViewName($view_name);
58 if (Ethna::isError($r)) {
62 // add view(invoke parent class method)
63 $ret =& $this->_perform('View', $view_name, $opt_list);
64 if (Ethna::isError($ret) || $ret === false) {
69 if (isset($opt_list['template'])) {
70 $ret =& $this->_performTemplate($view_name, $opt_list);
71 if (Ethna::isError($ret) || $ret === false) {
80 * Special Function for generating template.
82 * @param string $target_name Template Name
83 * @param array $opt_list Option List.
86 function &_performTemplate($target_name, $opt_list)
89 if (isset($opt_list['basedir'])) {
90 $basedir = realpath(end($opt_list['basedir']));
96 if (isset($opt_list['skelfile'])) {
97 $skelfile = end($opt_list['skelfile']);
103 $ctl =& Ethna_Handle::getAppController(getcwd());
104 if (isset($opt_list['locale'])) {
105 $locale = end($opt_list['locale']);
106 if (!preg_match('/^[A-Za-z_]+$/', $locale)) {
107 return Ethna::raiseError("You specified locale, but invalid : $locale", 'usage');
110 if (Ethna::isError($ctl)) {
113 $locale = $ctl->getLocale();
118 if (isset($opt_list['encoding'])) {
119 $encoding = end($opt_list['encoding']);
120 if (function_exists('mb_list_encodings')) {
121 $supported_enc = mb_list_encodings();
122 if (!in_array($encoding, $supported_enc)) {
123 return Ethna::raiseError("Unknown Encoding : $encoding", 'usage');
127 if (Ethna::isError($ctl)) {
130 $encoding = $ctl->getClientEncoding();
134 $r =& Ethna_Generator::generate('Template', $basedir,
135 $target_name, $skelfile, $locale, $encoding);
136 if (Ethna::isError($r)) {
137 printf("error occurred while generating skelton. please see also following error message(s)\n\n");
146 * get handler's description
150 function getDescription()
153 add new view to project:
154 {$this->id} [options... ] [view name]
155 [options ...] are as follows.
156 [-b|--basedir=dir] [-s|--skelfile=file]
157 [-w|--with-unittest] [-u|--unittestskel=file]
158 [-t|--template] [-l|--locale] [-e|--encoding]
159 NOTICE: "-w" and "-u" options are ignored when you specify -t option.
160 "-l" and "-e" options are enabled when you specify -t option.
171 ethna {$this->id} [options... ] [view name]
172 [options ...] are as follows.
173 [-b|--basedir=dir] [-s|--skelfile=file]
174 [-w|--with-unittest] [-u|--unittestskel=file]
175 [-t|--template] [-l|--locale] [-e|--encoding]
176 NOTICE: "-w" and "-u" options are ignored when you specify -t option.
177 "-l" and "-e" options are enabled when you specify -t option.