@@ -47,6 +47,34 @@ abstract class HttpServer extends Server
4747 * @var array
4848 */
4949 public $ viewResolvePaths ;
50+
51+ /**
52+ * Input类
53+ * 通过继承 PG\MSF\Base\Input 来自定义,默认是 PG\MSF\Base\Input
54+ * 可以在配置文件中修改,例如:
55+ *
56+ * ```php
57+ * 'http' => [
58+ * 'input' => PG\MSF\Base\Input::class,
59+ * ]
60+ * ```
61+ * @var Input
62+ */
63+ public $ input ;
64+
65+ /**
66+ * Output类
67+ * 通过继承 PG\MSF\Base\Output 来自定义,默认是 PG\MSF\Base\Output
68+ * 可以在配置文件中修改,例如:
69+ *
70+ * ```php
71+ * 'http' => [
72+ * 'output' => PG\MSF\Base\Output::class,
73+ * ]
74+ * ```
75+ * @var Output
76+ */
77+ public $ output ;
5078
5179 /**
5280 * HttpServer constructor.
@@ -82,6 +110,14 @@ public function setConfig()
82110 $ this ->httpEnable = $ this ->config ->get ('http_server.enable ' , true );
83111 $ this ->httpSocketName = $ this ->config ['http_server ' ]['socket ' ];
84112 $ this ->httpPort = $ this ->config ['http_server ' ]['port ' ];
113+ $ this ->input = $ this ->config ->get ('http.input ' , Input::class);
114+ if (is_array ($ this ->input )) {
115+ $ this ->input = $ this ->input ['class ' ] ?? Input::class;
116+ }
117+ $ this ->output = $ this ->config ->get ('http.output ' , Output::class);
118+ if (is_array ($ this ->output )) {
119+ $ this ->output = $ this ->output ['class ' ] ?? Output::class;
120+ }
85121 return $ this ;
86122 }
87123
@@ -231,12 +267,12 @@ public function onRequest($request, $response)
231267 /**
232268 * @var $input Input
233269 */
234- $ input = $ instance ->context ->getObjectPool ()->get (Input::class );
270+ $ input = $ instance ->context ->getObjectPool ()->get ($ this -> input );
235271 $ input ->set ($ request );
236272 /**
237273 * @var $output Output
238274 */
239- $ output = $ instance ->context ->getObjectPool ()->get (Output::class , [$ instance ]);
275+ $ output = $ instance ->context ->getObjectPool ()->get ($ this -> output , [$ instance ]);
240276 $ output ->set ($ request , $ response );
241277
242278 $ instance ->context ->setInput ($ input );
0 commit comments