Skip to content

Commit bcde590

Browse files
通过配置自定义Input类和Output类
通过继承 PG\MSF\Base\Input 和 PG\MSF\Base\Output 来自定义,然后在配置文件中增加 'http' => [ 'input' => PG\MSF\Base\Input::class, 'output' => PG\MSF\Base\Output::class, ]
1 parent a549217 commit bcde590

3 files changed

Lines changed: 33 additions & 6 deletions

File tree

src/Helpers/Context.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
namespace PG\MSF\Helpers;
1010

1111
use PG\Context\AbstractContext;
12-
use PG\Log\PGLog;
1312
use PG\MSF\Base\Input;
1413
use PG\MSF\Base\Output;
1514
use PG\MSF\Base\Pool;

src/HttpServer.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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,8 @@ 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+
$this->output = $this->config->get('http.output', Output::class);
85115
return $this;
86116
}
87117

@@ -231,12 +261,12 @@ public function onRequest($request, $response)
231261
/**
232262
* @var $input Input
233263
*/
234-
$input = $instance->context->getObjectPool()->get(Input::class);
264+
$input = $instance->context->getObjectPool()->get($this->input);
235265
$input->set($request);
236266
/**
237267
* @var $output Output
238268
*/
239-
$output = $instance->context->getObjectPool()->get(Output::class, [$instance]);
269+
$output = $instance->context->getObjectPool()->get($this->output, [$instance]);
240270
$output->set($request, $response);
241271

242272
$instance->context->setInput($input);

src/Rest/Controller.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
namespace PG\MSF\Rest;
1010

11-
use PG\MSF\Base\Output;
12-
1311
/**
1412
* Class Controller
1513
* @package PG\MSF\Rest
@@ -137,7 +135,7 @@ public function outputJson($data = null, $message = '', $status = 200)
137135
*/
138136
public function outputOptions(array $options)
139137
{
140-
/* @var $output Output */
138+
/* @var $output \PG\MSF\Base\Output */
141139
$output = $this->getContext()->getOutput();
142140
$status = 200;
143141
if ($this->verb !== 'OPTIONS') {

0 commit comments

Comments
 (0)