2 // vim: foldmethod=marker
4 * Ethna_MockProject.php
6 * @author Yoshinari Takaoka <takaoka@beatcraft.com>
10 define('ETHNA_TEST_DIR', ETHNA_BASE . '/test');
11 define('ETHNA_TEST_PROJECT', 'mockproject');
12 define('ETHNA_TEST_SKELDIR', ETHNA_TEST_DIR . '/skel/');
15 * ethna command Emulator Class.
19 class Ethna_MockProject
30 * @param $basedir プロジェクトベースディレクトリ
31 * @param $project_name プロジェクト名
32 * @param $skel_dir スケルトンディレクトリ
35 function Ethna_MockProject($basedir = ETHNA_TEST_DIR,
36 $project_name = ETHNA_TEST_PROJECT,
37 $skel_dir = ETHNA_TEST_SKELDIR)
39 $this->basedir = $basedir;
40 $this->skel_dir = $skel_dir;
41 $this->project_name = $project_name;
42 $this->proj_basedir = "${basedir}/${project_name}";
43 $this->is_created = false;
48 * ethna add-project コマンドをエミュレートします。
51 * @return 成功したらtrue, 失敗したらEthna_Error
55 $this->is_created = true;
57 if (!is_dir($this->proj_basedir)) {
60 $r = Ethna_Util::mkdir($this->proj_basedir, 0775);
61 } while ($r == false || is_dir($this->proj_basedir) == false);
64 // fire ethna add-project command
68 $this->basedir . '/' . $this->project_name,
73 $r = $this->runCmd($id, $options);
74 if (Ethna::isError($r)) {
83 * 実行することで、ethna コマンドをエミュレートします。
84 * (プロジェクトがない場合は作成されます)
87 * @param string $id コマンドID (e.x add-action)
88 * @param array $options コマンドラインオプション
89 * e.x ethna add-action -b /tmp test の場合
90 * array('-b', '/tmp', 'test') を指定
91 * @return 成功したらtrue, 失敗したらEthna_Error
93 function runCmd($id, $options = array())
95 if (($r = $this->create_ifnot_exists()) !== true) {
99 // supplement basedir option.
100 $in_basedir_opt = false;
101 foreach ($options as $opt) {
102 if ($opt == '-b' || $opt == '--basedir') {
103 $in_basedir_opt = true;
106 if (!$in_basedir_opt) {
107 $base_opt = array('-b', $this->proj_basedir);
108 $options = array_merge($base_opt, $options);
111 $eh =& new Ethna_Handle();
112 $handler =& $eh->getHandler($id);
113 if (Ethna::isError($handler)) {
117 ob_start(); // supress output.
118 $handler->setArgList($options);
119 $r = $handler->perform();
122 if (Ethna::isError($r)) {
130 * 作成したプロジェクトのコントローラクラス
132 * (プロジェクトがない場合は作成されます)
135 * @return Ethna_Controller コントローラクラスのインスタンス
138 function &getController()
140 if (($r = $this->create_ifnot_exists()) !== true) {
143 return Ethna_Handle::getAppController($this->proj_basedir);
147 * 作成したプロジェクトのベースディレクトリを取得します。
150 * @return string プロジェクトのベースディレクトリ
152 function getBaseDir()
154 return $this->proj_basedir;
164 Ethna_Util::purgeDir($this->proj_basedir);
168 * プロジェクトが既に作成されているかをチェックし,
172 * @return boolean 既に作成している場合はtrue.
173 * プロジェクトの作成に失敗したらEthna_Error
175 function create_ifnot_exists()
177 if ($this->is_created === false) {
178 $r = $this->create();
179 if (Ethna::isError($r)) {