Source for file AddAction.php

Documentation is available at AddAction.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  AddAction.php
  5.  *
  6.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id: 4251c3e6ce22b14f40304769b50a84959cdd7724 $
  10.  */
  11.  
  12. // {{{ Ethna_Plugin_Handle_AddAction
  13. /**
  14.  *  add-action handler
  15.  *
  16.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  17.  *  @access     public
  18.  *  @package    Ethna
  19.  */
  20. {
  21.     /**
  22.      *  add action
  23.      *
  24.      *  @access public
  25.      */
  26.     function perform()
  27.     {
  28.         //
  29.         //  '-w[with-unittest]' and '-u[unittestskel]' option
  30.         //  are not intuisive, but I dare to define them because
  31.         //  -t and -s option are reserved by add-[action|view] handle
  32.         //  and Ethna_Getopt cannot interpret two-character option.
  33.         //
  34.         $r $this->_getopt(
  35.                   array('basedir=',
  36.                         'skelfile=',
  37.                         'gateway=',
  38.                         'with-unittest',
  39.                         'unittestskel=',
  40.                   )
  41.              );
  42.         if (Ethna::isError($r)) {
  43.             return $r;
  44.         }
  45.         list($opt_list$arg_list$r;
  46.  
  47.         // action_name
  48.         $action_name array_shift($arg_list);
  49.         if ($action_name == null{
  50.             return Ethna::raiseError('action name isn\'t set.''usage');
  51.         }
  52.         $r Ethna_Controller::checkActionName($action_name);
  53.         if (Ethna::isError($r)) {
  54.             return $r;
  55.         }
  56.  
  57.         $ret $this->_perform('Action'$action_name$opt_list);
  58.         return $ret;
  59.     }
  60.  
  61.     /**
  62.      *  @access protected
  63.      */
  64.     function &_perform($target$target_name$opt_list)
  65.     {
  66.         // basedir
  67.         if (isset($opt_list['basedir'])) {
  68.             $basedir realpath(end($opt_list['basedir']));
  69.         else {
  70.             $basedir getcwd();
  71.         }
  72.  
  73.         // skelfile
  74.         if (isset($opt_list['skelfile'])) {
  75.             $skelfile end($opt_list['skelfile']);
  76.         else {
  77.             $skelfile null;
  78.         }
  79.         
  80.         // gateway
  81.         if (isset($opt_list['gateway'])) {
  82.             $gateway 'GATEWAY_' strtoupper(end($opt_list['gateway']));
  83.             if (defined($gateway)) {
  84.                 $gateway constant($gateway);
  85.             else {
  86.                 return Ethna::raiseError('unknown gateway''usage');
  87.             }
  88.         else {
  89.             $gateway GATEWAY_WWW;
  90.         }
  91.         
  92.         //  possible target is Action, View.
  93.         $r Ethna_Generator::generate($target$basedir,
  94.                                         $target_name$skelfile$gateway);
  95.         if (Ethna::isError($r)) {
  96.             printf("error occurred while generating skelton. please see also following error message(s)\n\n");
  97.             return $r;
  98.         }
  99.  
  100.         //
  101.         //  if specified, generate corresponding testcase,
  102.         //  except for template.
  103.         //
  104.         if ($target != 'Template' && isset($opt_list['with-unittest'])) {
  105.             $testskel (isset($opt_list['unittestskel']))
  106.                       ? end($opt_list['unittestskel'])
  107.                       : null;
  108.             $r Ethna_Generator::generate("{$target}Test"$basedir$target_name$testskel$gateway);
  109.             if (Ethna::isError($r)) {
  110.                 printf("error occurred while generating action test skelton. please see also following error message(s)\n\n");
  111.                 return $r;
  112.             }
  113.         }  
  114.  
  115.         $true true;
  116.         return $true;
  117.     }
  118.  
  119.     /**
  120.      *  get handler's description
  121.      *
  122.      *  @access public
  123.      */
  124.     function getDescription()
  125.     {
  126.         return <<<EOS
  127. add new action to project:
  128.     {$this->id} [-b|--basedir=dir] [-s|--skelfile=file] [-g|--gateway=www|cli|xmlrpc] [-w|--with-unittest] [-u|--unittestskel=file] [action]
  129.  
  130. EOS;
  131.     }
  132.  
  133.     /**
  134.      *  @access public
  135.      */
  136.     function getUsage()
  137.     {
  138.         return <<<EOS
  139. ethna {$this->id} [-b|--basedir=dir] [-s|--skelfile=file] [-g|--gateway=www|cli|xmlrpc] [-w|--with-unittest] [-u|--unittestskel=file] [action]
  140.  
  141. EOS;
  142.     }
  143. }
  144. // }}}

Documentation generated on Fri, 11 Nov 2011 03:57:26 +0900 by phpDocumentor 1.4.3