@@ -21,35 +21,6 @@ class Response implements ResponseInterface
2121 use StatusCodesTrait;
2222 use MessageMethodsTrait;
2323
24- private int $ status ;
25- private string $ reason ;
26-
27- /**
28- * @param int $statusCode Normally one of the status codes defined by RFC 7231 section 6
29- * @param ?StreamInterface $body
30- * @param array $headers Associative array of header strings or arrays of header strings
31- * @param array $params Associative array with following keys and its default values
32- * when key is not present or its value is null:
33- * - version - http protocol version (default: '1.1')
34- * - reason - reason phrase normally associated with $statusCode, so by
35- * default it will be resolved from it.
36- *
37- * @see https://tools.ietf.org/html/rfc7231#section-6
38- * @see StatusCodesTrait
39- */
40- public function __construct (
41- int $ statusCode ,
42- ?StreamInterface $ body = null ,
43- array $ headers = [],
44- array $ params = []
45- ) {
46- $ this ->status = $ this ->validStatusCode ($ statusCode );
47- $ this ->body = $ body ?? Stream::fromBodyString ('' );
48- $ this ->reason = $ this ->validReasonPhrase ($ params ['reason ' ] ?? '' );
49- $ this ->version = isset ($ params ['version ' ]) ? $ this ->validProtocolVersion ($ params ['version ' ]) : '1.1 ' ;
50- $ this ->loadHeaders ($ headers );
51- }
52-
5324 public static function text (string $ text , int $ statusCode = 200 ): self
5425 {
5526 return new self ($ statusCode , Stream::fromBodyString ($ text ), ['Content-Type ' => 'text/plain ' ]);
@@ -107,6 +78,35 @@ public static function notFound(?StreamInterface $body = null): self
10778 return new self (404 , $ body );
10879 }
10980
81+ private int $ status ;
82+ private string $ reason ;
83+
84+ /**
85+ * @param int $statusCode Normally one of the status codes defined by RFC 7231 section 6
86+ * @param ?StreamInterface $body
87+ * @param array $headers Associative array of header strings or arrays of header strings
88+ * @param array $params Associative array with following keys and its default values
89+ * when key is not present or its value is null:
90+ * - version - http protocol version (default: '1.1')
91+ * - reason - reason phrase normally associated with $statusCode, so by
92+ * default it will be resolved from it.
93+ *
94+ * @see https://tools.ietf.org/html/rfc7231#section-6
95+ * @see StatusCodesTrait
96+ */
97+ public function __construct (
98+ int $ statusCode ,
99+ ?StreamInterface $ body = null ,
100+ array $ headers = [],
101+ array $ params = []
102+ ) {
103+ $ this ->status = $ this ->validStatusCode ($ statusCode );
104+ $ this ->body = $ body ?? Stream::fromBodyString ('' );
105+ $ this ->reason = $ this ->validReasonPhrase ($ params ['reason ' ] ?? '' );
106+ $ this ->version = isset ($ params ['version ' ]) ? $ this ->validProtocolVersion ($ params ['version ' ]) : '1.1 ' ;
107+ $ this ->loadHeaders ($ headers );
108+ }
109+
110110 public function getStatusCode (): int
111111 {
112112 return $ this ->status ;
0 commit comments