@@ -18,17 +18,24 @@ class Build
18
18
19
19
protected static $ controller = '<?php
20
20
namespace [MODULE]\Controller;
21
+
21
22
use Think\Controller;
22
- class [CONTROLLER]Controller extends Controller {
23
- public function index(){
24
- $this->show( \'<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>!</p><br/>版本 V{$Think.version}</div><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_55e75dfae343f5a1"></thinkad><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script> \', \'utf-8 \');
23
+
24
+ class [CONTROLLER]Controller extends Controller
25
+ {
26
+ public function index()
27
+ {
28
+ [CONTENT]
25
29
}
26
30
} ' ;
27
31
28
32
protected static $ model = '<?php
29
33
namespace [MODULE]\Model;
34
+
30
35
use Think\Model;
31
- class [MODEL]Model extends Model {
36
+
37
+ class [MODEL]Model extends Model
38
+ {
32
39
33
40
} ' ;
34
41
// 检测应用目录是否需要自动创建
@@ -88,24 +95,12 @@ public static function buildAppDir($module)
88
95
file_put_contents (APP_PATH . $ module . '/Conf/config ' . CONF_EXT , '.php ' == CONF_EXT ? "<?php \nreturn array( \n\t//'配置项'=>'配置值' \n); " : '' );
89
96
}
90
97
91
- // 生成模块的测试控制器
92
- if (defined ('BUILD_CONTROLLER_LIST ' )) {
93
- // 自动生成的控制器列表(注意大小写)
94
- $ list = explode (', ' , BUILD_CONTROLLER_LIST );
95
- foreach ($ list as $ controller ) {
96
- self ::buildController ($ module , $ controller );
97
- }
98
- } else {
99
- // 生成默认的控制器
100
- self ::buildController ($ module );
101
- }
102
- // 生成模块的模型
98
+ // 自动生成控制器类
99
+ self ::buildController ($ module , defined ('BUILD_CONTROLLER_LIST ' ) ? BUILD_CONTROLLER_LIST : C ('DEFAULT_CONTROLLER ' ));
100
+
101
+ // 自动生成模型类
103
102
if (defined ('BUILD_MODEL_LIST ' )) {
104
- // 自动生成的控制器列表(注意大小写)
105
- $ list = explode (', ' , BUILD_MODEL_LIST );
106
- foreach ($ list as $ model ) {
107
- self ::buildModel ($ module , $ model );
108
- }
103
+ self ::buildModel ($ module , BUILD_MODEL_LIST );
109
104
}
110
105
} else {
111
106
header ('Content-Type:text/html; charset=utf-8 ' );
@@ -139,36 +134,45 @@ public static function buildRuntime()
139
134
}
140
135
141
136
// 创建控制器类
142
- public static function buildController ($ module , $ controller = ' Index ' )
137
+ public static function buildController ($ module , $ controllers )
143
138
{
144
- $ file = APP_PATH . $ module . '/Controller/ ' . $ controller . 'Controller ' . EXT ;
145
- if (!is_file ($ file )) {
146
- $ content = str_replace (array ('[MODULE] ' , '[CONTROLLER] ' ), array ($ module , $ controller ), self ::$ controller );
147
- if (!C ('APP_USE_NAMESPACE ' )) {
148
- $ content = preg_replace ('/namespace\s(.*?);/ ' , '' , $ content , 1 );
149
- }
150
- $ dir = dirname ($ file );
151
- if (!is_dir ($ dir )) {
152
- mkdir ($ dir , 0755 , true );
139
+ $ list = is_array ($ controllers ) ? $ controllers : explode (', ' , $ controllers );
140
+ $ hello = '$this->show( \'<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>!</p><br/>版本 V{$Think.version}</div><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_55e75dfae343f5a1"></thinkad><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script> \', \'utf-8 \'); ' ;
141
+
142
+ foreach ($ list as $ controller ) {
143
+ $ hello = C ('DEFAULT_CONTROLLER ' ) == $ controller ? $ hello : '' ;
144
+ $ file = APP_PATH . $ module . '/Controller/ ' . $ controller . 'Controller ' . EXT ;
145
+ if (!is_file ($ file )) {
146
+ $ content = str_replace (array ('[MODULE] ' , '[CONTROLLER] ' , '[CONTENT] ' ), array ($ module , $ controller , $ hello ), self ::$ controller );
147
+ if (!C ('APP_USE_NAMESPACE ' )) {
148
+ $ content = preg_replace ('/namespace\s(.*?);/ ' , '' , $ content , 1 );
149
+ }
150
+ $ dir = dirname ($ file );
151
+ if (!is_dir ($ dir )) {
152
+ mkdir ($ dir , 0755 , true );
153
+ }
154
+ file_put_contents ($ file , $ content );
153
155
}
154
- file_put_contents ($ file , $ content );
155
156
}
156
157
}
157
158
158
159
// 创建模型类
159
- public static function buildModel ($ module , $ model )
160
+ public static function buildModel ($ module , $ models )
160
161
{
161
- $ file = APP_PATH . $ module . '/Model/ ' . $ model . 'Model ' . EXT ;
162
- if (!is_file ($ file )) {
163
- $ content = str_replace (array ('[MODULE] ' , '[MODEL] ' ), array ($ module , $ model ), self ::$ model );
164
- if (!C ('APP_USE_NAMESPACE ' )) {
165
- $ content = preg_replace ('/namespace\s(.*?);/ ' , '' , $ content , 1 );
166
- }
167
- $ dir = dirname ($ file );
168
- if (!is_dir ($ dir )) {
169
- mkdir ($ dir , 0755 , true );
162
+ $ list = is_array ($ models ) ? $ models : explode (', ' , $ models );
163
+ foreach ($ list as $ model ) {
164
+ $ file = APP_PATH . $ module . '/Model/ ' . $ model . 'Model ' . EXT ;
165
+ if (!is_file ($ file )) {
166
+ $ content = str_replace (array ('[MODULE] ' , '[MODEL] ' ), array ($ module , $ model ), self ::$ model );
167
+ if (!C ('APP_USE_NAMESPACE ' )) {
168
+ $ content = preg_replace ('/namespace\s(.*?);/ ' , '' , $ content , 1 );
169
+ }
170
+ $ dir = dirname ($ file );
171
+ if (!is_dir ($ dir )) {
172
+ mkdir ($ dir , 0755 , true );
173
+ }
174
+ file_put_contents ($ file , $ content );
170
175
}
171
- file_put_contents ($ file , $ content );
172
176
}
173
177
}
174
178
@@ -187,7 +191,6 @@ public static function buildDirSecure($dirs = array())
187
191
foreach ($ dirs as $ dir ) {
188
192
file_put_contents ($ dir . $ filename , $ content );
189
193
}
190
-
191
194
}
192
195
}
193
196
}
0 commit comments