@@ -69,6 +69,16 @@ class Manager
6969 */
7070 protected $ sandbox ;
7171
72+ /**
73+ * @var
74+ */
75+ protected $ sandboxMode ;
76+
77+ /**
78+ * @var bool
79+ */
80+ protected $ enableAccessLog = false ;
81+
7282 /**
7383 * @var AccessOutput
7484 */
@@ -90,6 +100,20 @@ class Manager
90100 'workerError ' , 'managerStart ' , 'managerStop ' , 'request ' ,
91101 ];
92102
103+ /**
104+ * 是否处理静态文件
105+ *
106+ * @var bool
107+ */
108+ protected $ handleStatic = false ;
109+
110+ /**
111+ * 静态文件目录
112+ *
113+ * @var
114+ */
115+ protected $ publicPath ;
116+
93117 /**
94118 * HTTP server manager constructor.
95119 *
@@ -306,6 +330,12 @@ public function onWorkerStart($server, $workerId)
306330 $ this ->setLaravelApp ();
307331 $ this ->bindToLaravelApp ();
308332 } else {
333+ $ config = $ this ->container ->make ('config ' );
334+ $ this ->handleStatic = $ config ->get ('swoole_http.handle_static_files ' , true );
335+ $ this ->publicPath = $ config ->get ('swoole_http.server.public_path ' , base_path ('public ' ));
336+ $ this ->enableAccessLog = $ config ->get ('swoole_http.server.enable_access_log ' , false );
337+ $ this ->sandboxMode = $ config ->get ('swoole_http.sandbox_mode ' , true );
338+
309339 $ this ->setProcessName ('worker ' );
310340 $ this ->createApplication ();
311341 $ this ->setLaravelApp ();
@@ -330,8 +360,7 @@ public function onRequest($swooleRequest, $swooleResponse)
330360
331361 try {
332362 // handle static file request first
333- $ handleStatic = $ this ->container ->make ('config ' )->get ('swoole_http.handle_static_files ' , true );
334- if ($ handleStatic && $ this ->handleStaticRequest ($ illuminateRequest , $ swooleResponse )) {
363+ if ($ this ->handleStatic && $ this ->handleStaticRequest ($ illuminateRequest , $ swooleResponse )) {
335364 return ;
336365 }
337366
@@ -352,7 +381,7 @@ public function onRequest($swooleRequest, $swooleResponse)
352381 }
353382 } finally {
354383 // request's access log
355- if ($ this ->container -> make ( ' config ' )-> get ( ' swoole_http.server.enable_access_log ' , false ) ) {
384+ if ($ this ->enableAccessLog ) {
356385 $ this ->accessOutput ->log ($ illuminateRequest , $ illuminateResponse ?? null );
357386 }
358387 // Reset on every request.
@@ -470,8 +499,7 @@ protected function handleStaticRequest($illuminateRequest, $swooleResponse)
470499 return false ;
471500 }
472501
473- $ publicPath = $ this ->container ->make ('config ' )->get ('swoole_http.server.public_path ' , base_path ('public ' ));
474- $ filename = $ publicPath . $ uri ;
502+ $ filename = $ this ->publicPath . $ uri ;
475503
476504 $ mime = "text/html " ;
477505 if (!$ isFile = file_exists ($ filename )) {
@@ -509,7 +537,7 @@ protected function handleStaticRequest($illuminateRequest, $swooleResponse)
509537 */
510538 protected function resetOnRequest ()
511539 {
512- if ($ this ->container -> make ( ' config ' )-> get ( ' swoole_http.sandbox_mode ' , true ) ) {
540+ if ($ this ->sandboxMode ) {
513541 // disable and recycle sandbox resource
514542 is_object ($ this ->sandbox ) && $ this ->sandbox ->disable ();
515543 }
@@ -565,7 +593,7 @@ protected function setLaravelApp()
565593 */
566594 protected function getFastApplication ($ illuminateRequest )
567595 {
568- if ($ this ->container -> make ( ' config ' )-> get ( ' swoole_http.sandbox_mode ' , true ) ) {
596+ if ($ this ->sandboxMode ) {
569597 // set current request to sandbox and enable sandbox
570598 $ this ->sandbox ->setRequest ($ illuminateRequest );
571599 $ this ->sandbox ->enable ();
@@ -581,7 +609,7 @@ protected function getFastApplication($illuminateRequest)
581609 protected function setSandbox ()
582610 {
583611 // set application to sandbox environment
584- if ($ this ->container -> make ( ' config ' )-> get ( ' swoole_http.sandbox_mode ' , true ) ) {
612+ if ($ this ->sandboxMode ) {
585613 $ this ->sandbox = Sandbox::make ($ this ->getApplication ());
586614 }
587615 }
0 commit comments