githubtrue/backend/vendor/illuminate/http/ResponseTrait.php @ b50f8ebd
1 |
<?php
|
---|---|
2 |
|
3 |
namespace Illuminate\Http; |
4 |
|
5 |
use Illuminate\Http\Exception\HttpResponseException; |
6 |
|
7 |
trait ResponseTrait |
8 |
{
|
9 |
/**
|
10 |
* Get the status code for the response.
|
11 |
*
|
12 |
* @return int
|
13 |
*/
|
14 |
public function status() |
15 |
{
|
16 |
return $this->getStatusCode(); |
17 |
}
|
18 |
|
19 |
/**
|
20 |
* Get the content of the response.
|
21 |
*
|
22 |
* @return string
|
23 |
*/
|
24 |
public function content() |
25 |
{
|
26 |
return $this->getContent(); |
27 |
}
|
28 |
|
29 |
/**
|
30 |
* Set a header on the Response.
|
31 |
*
|
32 |
* @param string $key
|
33 |
* @param string $value
|
34 |
* @param bool $replace
|
35 |
* @return $this
|
36 |
*/
|
37 |
public function header($key, $value, $replace = true) |
38 |
{
|
39 |
$this->headers->set($key, $value, $replace); |
40 |
|
41 |
return $this; |
42 |
}
|
43 |
|
44 |
/**
|
45 |
* Add an array of headers to the response.
|
46 |
*
|
47 |
* @param array $headers
|
48 |
* @return $this
|
49 |
*/
|
50 |
public function withHeaders(array $headers) |
51 |
{
|
52 |
foreach ($headers as $key => $value) { |
53 |
$this->headers->set($key, $value); |
54 |
}
|
55 |
|
56 |
return $this; |
57 |
}
|
58 |
|
59 |
/**
|
60 |
* Add a cookie to the response.
|
61 |
*
|
62 |
* @param \Symfony\Component\HttpFoundation\Cookie|mixed $cookie
|
63 |
* @return $this
|
64 |
*/
|
65 |
public function cookie($cookie) |
66 |
{
|
67 |
return call_user_func_array([$this, 'withCookie'], func_get_args()); |
68 |
}
|
69 |
|
70 |
/**
|
71 |
* Add a cookie to the response.
|
72 |
*
|
73 |
* @param \Symfony\Component\HttpFoundation\Cookie|mixed $cookie
|
74 |
* @return $this
|
75 |
*/
|
76 |
public function withCookie($cookie) |
77 |
{
|
78 |
if (is_string($cookie) && function_exists('cookie')) { |
79 |
$cookie = call_user_func_array('cookie', func_get_args()); |
80 |
}
|
81 |
|
82 |
$this->headers->setCookie($cookie); |
83 |
|
84 |
return $this; |
85 |
}
|
86 |
|
87 |
/**
|
88 |
* Throws the response in a HttpResponseException instance.
|
89 |
*
|
90 |
* @throws \Illuminate\Http\Exception\HttpResponseException
|
91 |
*/
|
92 |
public function throwResponse() |
93 |
{
|
94 |
throw new HttpResponseException($this); |
95 |
}
|
96 |
}
|