File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Http ответ веб-приложения.
4+ * @package evas-php\evas-web
5+ * @author Egor Vasyakin <egor@evas-php.com>
6+ */
7+ namespace Evas \Web ;
8+
9+ use Evas \Http \HttpResponse ;
10+
11+ class WebResponse extends HttpResponse
12+ {
13+ /**
14+ * Реализация реальной отправка ответа.
15+ */
16+ public function realSend ()
17+ {
18+ $ this ->applyHeaders ();
19+ echo $ this ->getBody ();
20+ }
21+
22+ /**
23+ * Применить код статуса.
24+ * @param int|null код статуса
25+ * @param string|null кастомный текст статуса
26+ * @return self
27+ */
28+ public function applyStatusCode (int $ code = null , string $ statusText = null )
29+ {
30+ if ($ code ) $ this ->withStatusCode ($ code , $ statusText );
31+ header ("HTTP/1.1 $ this ->statusCode $ this ->statusText " );
32+ return $ this ;
33+ }
34+
35+ /**
36+ * Применение свойств cookie.
37+ * @return self
38+ */
39+ protected function applyCookies ()
40+ {
41+ if (!empty ($ this ->cookies )) foreach ($ this ->cookies as &$ cookie ) {
42+ $ this ->withHeader ('Set-Cookie ' , (string ) $ cookie );
43+ }
44+ return $ this ;
45+ }
46+
47+ /**
48+ * Применение установленных заголовков вместе со статусом и куки.
49+ * @return self
50+ */
51+ public function applyHeaders ()
52+ {
53+ $ this ->applyStatusCode ();
54+ $ this ->applyCookies ();
55+ foreach ($ this ->headers as $ name => $ value ) {
56+ header ("$ name: $ value " );
57+ }
58+ return $ this ;
59+ }
60+ }
You can’t perform that action at this time.
0 commit comments