44 */
55namespace Evas \Http ;
66
7- use \ Exception ;
7+ use Evas \ Http \ HttpException ;
88use Evas \Http \BodyTrait ;
99use Evas \Http \HeadersTrait ;
1010use Evas \Http \ResponseInterface ;
@@ -51,16 +51,28 @@ class Response implements ResponseInterface
5151
5252 /**
5353 * Установка кода статуса.
54- * @param int
55- * @throws Exception
54+ * @param int код статуса
55+ * @param string|null кастомный текст статуса
56+ * @throws HttpException
5657 * @return self
5758 */
58- public function withStatusCode (int $ code )
59+ public function withStatusCode (int $ code, string $ statusText = null )
5960 {
6061 $ this ->statusCode = $ code ;
61- $ this ->statusText = static ::HTTP_STATUSES [$ this ->statusCode ] ?? null ;
62+ return $ this ->withStatusText ($ statusText );
63+ }
64+
65+ /**
66+ * Установка текста статуса.
67+ * @param string|null кастомный текст статуса
68+ * @throws HttpException
69+ * @return self
70+ */
71+ public function withStatusText (string $ statusText = null )
72+ {
73+ $ this ->statusText = $ statusText ?? static ::HTTP_STATUSES [$ this ->statusCode ] ?? null ;
6274 if (! $ this ->statusText ) {
63- throw new Exception (static ::ERROR_HTTP_STATUS_NOT_FOUND . " $ this ->statusCode " );
75+ throw new HttpException (static ::ERROR_HTTP_STATUS_NOT_FOUND . " $ this ->statusCode " );
6476 }
6577 return $ this ;
6678 }
@@ -75,8 +87,7 @@ public function write(string $message)
7587 $ this ->body .= $ message ;
7688 return $ this ;
7789 }
78-
79-
90+
8091
8192 /**
8293 * Получение кода статуса.
@@ -87,6 +98,14 @@ public function getStatusCode(): int
8798 return $ this ->statusCode ;
8899 }
89100
101+ /**
102+ * Получение текста статуса.
103+ * @return string|null
104+ */
105+ public function getStatusText (): ?string
106+ {
107+ return $ this ->statusText ?? static ::HTTP_STATUSES [$ this ->statusCode ] ?? null ;
108+ }
90109
91110
92111 /**
0 commit comments