4
4
5
5
use App \Facades \App ;
6
6
use App \Kernel \View ;
7
+ use Laminas \HttpHandlerRunner \Emitter \SapiEmitter ;
7
8
use Psr \Http \Message \ResponseInterface ;
8
9
use Psr \Http \Message \StreamInterface ;
9
10
use function get_class ;
@@ -109,11 +110,6 @@ class Response implements ResponseInterface
109
110
*/
110
111
private $ cookies ;
111
112
112
- /**
113
- * @var int[]
114
- */
115
- private $ accept_code = [];
116
-
117
113
/**
118
114
* Response constructor.
119
115
* @param string|StreamInterface $content
@@ -141,12 +137,6 @@ public function __construct(
141
137
$ this ->stream = $ content ;
142
138
}
143
139
$ this ->cookies = Cookie::makeFromArray ($ this ->getHeader ('Set-Cookie ' ));
144
- // Has session
145
- $ session_cookie = SessionManager::makeCookie ();
146
- if ($ session_cookie !== null ) {
147
- $ this ->cookies [$ session_cookie ->getName ()] = $ session_cookie ;
148
- $ this ->updateCookieHeader ();
149
- }
150
140
}
151
141
152
142
/**
@@ -234,6 +224,11 @@ public static function make(
234
224
return new static ($ content , $ status , $ headers );
235
225
}
236
226
227
+ public function send (): void
228
+ {
229
+ (new SapiEmitter ())->emit ($ this );
230
+ }
231
+
237
232
/**
238
233
* @inheritDoc
239
234
*/
@@ -357,10 +352,10 @@ public function hasCookie(string $name): bool
357
352
* @param Cookie $cookie
358
353
* @return Response
359
354
*/
360
- public function withCookie (string $ name , Cookie $ cookie ): Response
355
+ public function withCookie (Cookie $ cookie ): Response
361
356
{
362
357
$ new = clone $ this ;
363
- $ new ->cookies [$ name ] = $ cookie ;
358
+ $ new ->cookies [$ cookie -> getName () ] = $ cookie ;
364
359
$ new ->updateCookieHeader ();
365
360
return $ new ;
366
361
}
@@ -398,7 +393,6 @@ public function cookie(
398
393
bool $ http_only = false
399
394
): Response {
400
395
return $ this ->withCookie (
401
- $ name ,
402
396
Cookie::make ($ name , $ value )
403
397
->withMaxAge ($ expire )
404
398
->withPath ($ path )
@@ -416,7 +410,7 @@ public function withCookies(array $cookies): Response
416
410
{
417
411
$ result = clone $ this ;
418
412
foreach ($ cookies as $ cookie ) {
419
- $ result = $ result ->withCookie ($ cookie-> getName (), $ cookie );
413
+ $ result = $ result ->withCookie ($ cookie );
420
414
}
421
415
return $ result ;
422
416
}
@@ -430,13 +424,6 @@ public function withCookies(array $cookies): Response
430
424
*/
431
425
private function convert ($ content ): string
432
426
{
433
- if (
434
- !in_array ($ this ->status , $ this ->accept_code ) &&
435
- $ this ->status >= 400 &&
436
- !App::make (Request::class)->ajax ()
437
- ) {
438
- return view ('errors/errors ' , $ content )->render ();
439
- }
440
427
if ($ content === null ) {
441
428
return '' ;
442
429
}
0 commit comments