File tree Expand file tree Collapse file tree 6 files changed +33
-15
lines changed Expand file tree Collapse file tree 6 files changed +33
-15
lines changed Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ foreach ($argv as $v) {
69
69
}
70
70
71
71
// 设置cli模式
72
- putenv ('IS_CLI=true ' );
72
+ putenv ('IS_CLI=yes ' );
73
73
$ method = $ input ['method ' ];
74
74
$ method = explode ('. ' , $ method );
75
75
$ input ['module ' ] = $ method [0 ];
Original file line number Diff line number Diff line change @@ -68,6 +68,17 @@ class App
68
68
*/
69
69
public static $ app ;
70
70
71
+ /**
72
+ * 是否输出响应结果
73
+ *
74
+ * 默认输出
75
+ *
76
+ * cli模式 访问路径为空 不输出
77
+ *
78
+ * @var boolean
79
+ */
80
+ private $ notOutput = false ;
81
+
71
82
/**
72
83
* 服务容器
73
84
*
@@ -199,7 +210,7 @@ public function callSelf($method = '', $uri = '')
199
210
}
200
211
$ request = self ::$ container ->getSingle ('request ' );
201
212
$ request ->method = $ method ;
202
- $ router = self ::$ container ->getSingle ('router ' );
213
+ $ router = self ::$ container ->getSingle ('router ' );
203
214
$ router ->moduleName = $ requestUri [0 ];
204
215
$ router ->controllerName = $ requestUri [1 ];
205
216
$ router ->actionName = $ requestUri [2 ];
@@ -233,6 +244,9 @@ public function run(Closure $request)
233
244
*/
234
245
public function response (Closure $ closure )
235
246
{
247
+ if ($ this ->notOutput === true ) {
248
+ return ;
249
+ }
236
250
// $closure()->reponse($this->responseData);
237
251
$ closure ()->restSuccess ($ this ->responseData );
238
252
}
Original file line number Diff line number Diff line change @@ -109,11 +109,11 @@ class Request
109
109
public function __construct (App $ app )
110
110
{
111
111
$ this ->serverParams = $ _SERVER ;
112
- $ this ->method = strtolower ($ _SERVER ['REQUEST_METHOD ' ]);
113
- $ this ->serverIp = $ _SERVER ['REMOTE_ADDR ' ];
114
- $ this ->clientIp = $ _SERVER ['SERVER_ADDR ' ];
115
- $ this ->beginTime = $ _SERVER ['REQUEST_TIME_FLOAT ' ];
116
- if ($ app ->isCli === 'true ' ) {
112
+ $ this ->method = isset ( $ _SERVER [ ' REQUEST_METHOD ' ])? strtolower ($ _SERVER ['REQUEST_METHOD ' ]) : ' get ' ;
113
+ $ this ->serverIp = isset ( $ _SERVER ['REMOTE_ADDR ' ])? $ _SERVER [ ' REMOTE_ADDR ' ] : '' ;
114
+ $ this ->clientIp = isset ( $ _SERVER ['SERVER_ADDR ' ])? $ _SERVER [ ' SERVER_ADDR ' ] : '' ;
115
+ $ this ->beginTime = isset ( $ _SERVER ['REQUEST_TIME_FLOAT ' ])? $ _SERVER [ ' REQUEST_TIME_FLOAT ' ] : time ( true ) ;
116
+ if ($ app ->isCli === 'yes ' ) {
117
117
// cli 模式
118
118
$ this ->requestParams = $ _REQUEST ['argv ' ];
119
119
$ this ->getParams = $ _REQUEST ['argv ' ];
Original file line number Diff line number Diff line change @@ -222,7 +222,7 @@ public function register(App $app)
222
222
223
223
/* 路由策略 */
224
224
$ this ->routeStrategy = 'pathinfo ' ;
225
- if (strpos ($ this ->requestUri , 'index.php ' ) || $ app ->isCli === 'true ' ) {
225
+ if (strpos ($ this ->requestUri , 'index.php ' ) || $ app ->isCli === 'yes ' ) {
226
226
$ this ->routeStrategy = 'general ' ;
227
227
}
228
228
@@ -308,10 +308,12 @@ public function pathinfo()
308
308
preg_match_all ('/^\/(.*)/ ' , $ this ->requestUri , $ uri );
309
309
}
310
310
311
+ // 使用默认模块/控制器/操作逻辑
311
312
if (!isset ($ uri [1 ][0 ]) || empty ($ uri [1 ][0 ])) {
312
- /*
313
- * 使用默认模块/控制器/操作逻辑
314
- */
313
+ // CLI 模式不输出
314
+ if ($ this ->app ->isCli === 'yes ' ) {
315
+ $ this ->app ->notOutput = true ;
316
+ }
315
317
return ;
316
318
}
317
319
$ uri = $ uri [1 ][0 ];
@@ -382,6 +384,9 @@ private function userDefined()
382
384
}
383
385
$ map = $ this ->$ method ;
384
386
$ this ->app ->responseData = $ map [$ uri ]($ app );
387
+ if ($ this ->app ->isCli === 'yes ' ) {
388
+ $ this ->app ->notOutput = false ;
389
+ }
385
390
return true ;
386
391
}
387
392
Original file line number Diff line number Diff line change 21
21
</filter >
22
22
<php >
23
23
<env name =" APP_ENV" value =" testing" />
24
+ <env name =" IS_CLI" value =" yes" />
24
25
</php >
25
26
</phpunit >
Original file line number Diff line number Diff line change 12
12
namespace Tests \Demo ;
13
13
14
14
use Tests \TestCase ;
15
- use App \ Demo \ Controllers \ Index ;
15
+ use Framework \ App ;
16
16
17
17
/**
18
18
* 单元测试 示例
@@ -26,11 +26,9 @@ class DemoTest extends TestCase
26
26
*/
27
27
public function testDemo ()
28
28
{
29
- $ index = new Index ();
30
-
31
29
$ this ->assertEquals (
32
30
'Hello Easy PHP ' ,
33
- $ index -> hello ( )
31
+ App:: $ app -> get ( ' demo/index/hello ' )
34
32
);
35
33
}
36
34
}
You can’t perform that action at this time.
0 commit comments