OSDN Git Service

cfc7cb87c16c3dfee8890c1bd28bbd98df19ca68
[ethna/ethna.git] / class / Plugin / Generator / Ethna_Plugin_Generator_ViewTest.php
1 <?php
2 // vim: foldmethod=marker
3 /**
4  *  Ethna_Plugin_Generator_ViewTest.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_Plugin_Generator_ViewTest
13 /**
14  *  ¥¹¥±¥ë¥È¥óÀ¸À®¥¯¥é¥¹
15  *
16  *  @author     Masaki Fujimoto <fujimoto@php.net>
17  *  @access     public
18  *  @package    Ethna
19  */
20 class Ethna_Plugin_Generator_ViewTest extends Ethna_Plugin_Generator
21 {
22     /**
23      *  ¥Ó¥å¡¼Íѥƥ¹¥È¤Î¥¹¥±¥ë¥È¥ó¤òÀ¸À®¤¹¤ë
24      *
25      *  @access public
26      *  @param  string  $forward_name   ¥Ó¥å¡¼Ì¾
27      *  @param  string  $skelton        ¥¹¥±¥ë¥È¥ó¥Õ¥¡¥¤¥ë̾
28      *  @return true|Ethna_Error        true:À®¸ù Ethna_Error:¼ºÇÔ
29      */
30     function &generate($forward_name, $skelton = null, $gateway = GATEWAY_WWW)
31     {
32         $view_dir = $this->ctl->getViewdir();
33         $view_class = $this->ctl->getDefaultViewClass($forward_name, $gateway);
34         $view_path = $this->ctl->getDefaultViewPath($forward_name . 'Test');
35
36         // entity
37         $entity = $view_dir . $view_path;
38         Ethna_Util::mkdir(dirname($entity), 0755);
39
40         // skelton
41         if ($skelton === null) {
42             $skelton = 'skel.view_test.php';
43         }
44
45         // macro
46         $macro = array();
47         $macro['project_id'] = $this->ctl->getAppId();
48         $macro['forward_name'] = $forward_name;
49         $macro['view_class'] = $view_class;
50         $macro['view_path'] = $view_path;
51
52         // user macro
53         $user_macro = $this->_getUserMacro();
54         $macro = array_merge($macro, $user_macro);
55
56
57         // generate
58         if (file_exists($entity)) {
59             printf("file [%s] already exists -> skip\n", $entity);
60         } else if ($this->_generateFile($skelton, $entity, $macro) == false) {
61             printf("[warning] file creation failed [%s]\n", $entity);
62         } else {
63             printf("view test(s) successfully created [%s]\n", $entity);
64         }
65
66         $true = true;
67         return $true;
68     }
69 }
70 // }}}
71 ?>