OSDN Git Service

Merge branch 'feature/php5.3-compatible2' into develop
[ethna/ethna.git] / class / Generator.php
1 <?php
2 // vim: foldmethod=marker
3 /**
4  *  Generator.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$
10  */
11
12 // {{{ Ethna_Generator
13 /**
14  *  スケルトン生成クラス
15  *
16  *  @author     Masaki Fujimoto <fujimoto@php.net>
17  *  @access     public
18  *  @package    Ethna
19  */
20 class Ethna_Generator
21 {
22     /**
23      *  スケルトンを生成する
24      *
25      *  @access public
26      *  @param  string  $type       生成する対象
27      *  @param  string  $app_dir    アプリケーションのディレクトリ
28      *                              (nullのときはアプリケーションを特定しない)
29      *  @param  mixed   residue     プラグインのgenerate()にそのまま渡す
30      *  @static
31      */
32     public static function generate()
33     {
34         $arg_list   = func_get_args();
35         $type       = array_shift($arg_list);
36         $app_dir    = array_shift($arg_list);
37
38         if ($app_dir === null) {
39             $ctl = Ethna_Handle::getEthnaController();
40         } else {
41             $ctl = Ethna_Handle::getAppController($app_dir);
42         }
43         if (Ethna::isError($ctl)) {
44             return $ctl;
45         }
46
47         $plugin_manager = $ctl->getPlugin();
48         if (Ethna::isError($plugin_manager)) {
49             return $plugin_manager;
50         }
51
52         $generator = $plugin_manager->getPlugin('Generator', $type);
53         if (Ethna::isError($generator)) {
54             return $generator;
55         }
56         
57         // 引数はプラグイン依存とする
58         $ret = call_user_func_array(array(&$generator, 'generate'), $arg_list);
59         return $ret;
60     }
61
62     /**
63      *  スケルトンを削除する
64      *
65      *  @access public
66      *  @param  string  $type       生成する対象
67      *  @param  string  $app_dir    アプリケーションのディレクトリ
68      *                              (nullのときはアプリケーションを特定しない)
69      *  @param  mixed   residue     プラグインのremove()にそのまま渡す
70      *  @static
71      */
72     public static function remove()
73     {
74         $arg_list   = func_get_args();
75         $type       = array_shift($arg_list);
76         $app_dir    = array_shift($arg_list);
77
78         if ($app_dir === null) {
79             $ctl = Ethna_Handle::getEthnaController();
80         } else {
81             $ctl = Ethna_Handle::getAppController($app_dir);
82         }
83         if (Ethna::isError($ctl)) {
84             return $ctl;
85         }
86
87         $plugin_manager = $ctl->getPlugin();
88         if (Ethna::isError($plugin_manager)) {
89             return $plugin_manager;
90         }
91
92         $generator = $plugin_manager->getPlugin('Generator', $type);
93         if (Ethna::isError($generator)) {
94             return $generator;
95         }
96         
97         // 引数はプラグイン依存とする
98         $ret = call_user_func_array(array(&$generator, 'remove'), $arg_list);
99         return $ret;
100     }
101 }
102 // }}}