OSDN Git Service

- create ethna command idea branche
[ethna/ethna.git] / Idea_Plugin_Extlib / class / Plugin / Generator / EntryPoint.php
1 <?php
2 // vim: foldmethod=marker
3 /**
4  *  Ethna_Plugin_Generator_EntryPoint.php
5  *
6  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
7  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
8  *  @package    Ethna
9  *  @version    $Id$
10  */
11
12 // {{{ Ethna_Plugin_Generator_EntryPoint
13 /**
14  *  スケルトン生成クラス
15  *
16  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
17  *  @access     public
18  *  @package    Ethna
19  */
20 class Ethna_Plugin_Generator_EntryPoint extends Ethna_Plugin_Generator
21 {
22     /**
23      *  エントリポイントのスケルトンを生成する
24      *
25      *  @access public
26      *  @param  string  $skelton    スケルトンファイル名
27      *  @param  int     $gateway    ゲートウェイ
28      *  @return true|Ethna_Error    true:成功 Ethna_Error:失敗
29      */
30     function &generate($action_name, $skelton = null, $gateway = GATEWAY_WWW)
31     {
32         $true = true;
33
34         // entity
35         switch ($gateway) {
36         case GATEWAY_WWW:
37             $entity = sprintf("%s/%s.%s", $this->ctl->getDirectory('www'),
38                               $action_name, $this->ctl->getExt('php'));
39             break;
40         case GATEWAY_CLI:
41             $entity = sprintf("%s/%s.%s", $this->ctl->getDirectory('bin'),
42                               $action_name, $this->ctl->getExt('php'));
43             break;
44         default:
45             $ret =& Ethna::raiseError(
46                 'add-entry-point accepts only GATEWAY_WWW or GATEWAY_CLI.');
47             return $ret;
48         }
49
50         // skelton
51         if ($skelton === null) {
52             switch ($gateway) {
53             case GATEWAY_WWW:
54                 $skelton = 'skel.entry_www.php';
55                 break;
56             case GATEWAY_CLI:
57                 $skelton = 'skel.entry_cli.php';
58                 break;
59             }
60         }
61         if (file_exists($entity)) {
62             printf("file [%s] already exists -> skip\n", $entity);
63             return $true;
64         }
65
66         // macro
67         $macro = array();
68         $macro['project_id'] = $this->ctl->getAppId();
69         $macro['action_name'] = $action_name;
70         $macro['dir_app'] = $this->ctl->getDirectory('app');
71
72         // user macro
73         $user_macro = $this->_getUserMacro();
74         $macro = array_merge($macro, $user_macro);
75
76         // generate
77         $ret = $this->_generateFile($skelton, $entity, $macro);
78         if ($ret) {
79             printf("action script(s) successfully created [%s]\n", $entity);
80         } else {
81             printf("[warning] file creation failed [%s]\n", $entity);
82             return $true; // XXX: error handling
83         }
84
85         // chmod
86         if ($gateway === GATEWAY_CLI) {
87             // is needed?
88             //$ret = Ethna_Util::chmod($entity, 0777);
89         }
90             
91
92         return $true;
93     }
94 }
95 // }}}
96 ?>