@@ -27,14 +27,14 @@ |
||
| 27 | 27 | return $array; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - public static function converToObject(array $data) |
|
| 31 | - { |
|
| 32 | - $object = new \stdClass(); |
|
| 30 | + public static function converToObject(array $data) |
|
| 31 | + { |
|
| 32 | + $object = new \stdClass(); |
|
| 33 | 33 | |
| 34 | - foreach ($data as $key => $value) { |
|
| 35 | - $object->$key = $value; |
|
| 36 | - } |
|
| 34 | + foreach ($data as $key => $value) { |
|
| 35 | + $object->$key = $value; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - return $object; |
|
| 38 | + return $object; |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | \ No newline at end of file |
@@ -54,8 +54,8 @@ |
||
| 54 | 54 | return $this; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - private function set(string $key, $value) |
|
| 58 | - { |
|
| 59 | - $_GET[$key] = $value; |
|
| 60 | - } |
|
| 57 | + private function set(string $key, $value) |
|
| 58 | + { |
|
| 59 | + $_GET[$key] = $value; |
|
| 60 | + } |
|
| 61 | 61 | } |
| 62 | 62 | \ No newline at end of file |
@@ -54,8 +54,8 @@ |
||
| 54 | 54 | return $this; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - private function set(string $key, $value) |
|
| 58 | - { |
|
| 59 | - $_ENV[$key] = $value; |
|
| 60 | - } |
|
| 57 | + private function set(string $key, $value) |
|
| 58 | + { |
|
| 59 | + $_ENV[$key] = $value; |
|
| 60 | + } |
|
| 61 | 61 | } |
| 62 | 62 | \ No newline at end of file |
@@ -49,9 +49,9 @@ |
||
| 49 | 49 | { |
| 50 | 50 | unset($this->cookie[$key]); |
| 51 | 51 | |
| 52 | - unset($_COOKIE[$key]); |
|
| 52 | + unset($_COOKIE[$key]); |
|
| 53 | 53 | |
| 54 | - return $this; |
|
| 54 | + return $this; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | private function set(string $key, $value, $expire, $path, $domain, $secure, $httponly) |
@@ -63,56 +63,56 @@ |
||
| 63 | 63 | |
| 64 | 64 | public function getContent() |
| 65 | 65 | { |
| 66 | - if (!empty($_POST)) { |
|
| 67 | - return $_POST; |
|
| 68 | - } |
|
| 66 | + if (!empty($_POST)) { |
|
| 67 | + return $_POST; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | 70 | return file_get_contents("php://input"); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public function get(string $key) |
|
| 74 | - { |
|
| 75 | - return $this->server[$key]; |
|
| 76 | - } |
|
| 73 | + public function get(string $key) |
|
| 74 | + { |
|
| 75 | + return $this->server[$key]; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - public function all(): array |
|
| 79 | - { |
|
| 80 | - return $this->server; |
|
| 81 | - } |
|
| 78 | + public function all(): array |
|
| 79 | + { |
|
| 80 | + return $this->server; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - public function except(array $keys): array |
|
| 84 | - { |
|
| 85 | - return ArrayUtil::except($this->server, $keys); |
|
| 86 | - } |
|
| 83 | + public function except(array $keys): array |
|
| 84 | + { |
|
| 85 | + return ArrayUtil::except($this->server, $keys); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - public function only(array $keys): array |
|
| 89 | - { |
|
| 90 | - return ArrayUtil::only($this->server, $keys); |
|
| 91 | - } |
|
| 88 | + public function only(array $keys): array |
|
| 89 | + { |
|
| 90 | + return ArrayUtil::only($this->server, $keys); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - public function has(string $key): bool |
|
| 94 | - { |
|
| 95 | - return !empty($this->server[$key]); |
|
| 96 | - } |
|
| 93 | + public function has(string $key): bool |
|
| 94 | + { |
|
| 95 | + return !empty($this->server[$key]); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - public function add($key, $value): void |
|
| 99 | - { |
|
| 100 | - $this->server[$key] = $value; |
|
| 98 | + public function add($key, $value): void |
|
| 99 | + { |
|
| 100 | + $this->server[$key] = $value; |
|
| 101 | 101 | |
| 102 | - $this->set($key, $value); |
|
| 103 | - } |
|
| 102 | + $this->set($key, $value); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - public function remove(string $key): Server |
|
| 106 | - { |
|
| 107 | - unset($this->server[$key]); |
|
| 105 | + public function remove(string $key): Server |
|
| 106 | + { |
|
| 107 | + unset($this->server[$key]); |
|
| 108 | 108 | |
| 109 | - unset($_SERVER[$key]); |
|
| 109 | + unset($_SERVER[$key]); |
|
| 110 | 110 | |
| 111 | - return $this; |
|
| 112 | - } |
|
| 111 | + return $this; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - private function set(string $key, $value) |
|
| 115 | - { |
|
| 116 | - $_SERVER[$key] = $value; |
|
| 117 | - } |
|
| 114 | + private function set(string $key, $value) |
|
| 115 | + { |
|
| 116 | + $_SERVER[$key] = $value; |
|
| 117 | + } |
|
| 118 | 118 | } |
| 119 | 119 | \ No newline at end of file |
@@ -19,8 +19,8 @@ |
||
| 19 | 19 | protected function clearHeadersFromHeadersList($headers, $needle) |
| 20 | 20 | { |
| 21 | 21 | foreach ($headers as $header) { |
| 22 | - if(stripos($header,$needle) !== false) { |
|
| 23 | - $headerParts = explode(':',$header); |
|
| 22 | + if (stripos($header, $needle) !== false) { |
|
| 23 | + $headerParts = explode(':', $header); |
|
| 24 | 24 | return trim($headerParts[1]); |
| 25 | 25 | } |
| 26 | 26 | } |
@@ -49,13 +49,13 @@ |
||
| 49 | 49 | { |
| 50 | 50 | unset($this->session[$key]); |
| 51 | 51 | |
| 52 | - unset($_SESSION[$key]); |
|
| 52 | + unset($_SESSION[$key]); |
|
| 53 | 53 | |
| 54 | - return $this; |
|
| 54 | + return $this; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - private function set(string $key, $value) |
|
| 58 | - { |
|
| 59 | - $_SESSION[$key] = $value; |
|
| 60 | - } |
|
| 57 | + private function set(string $key, $value) |
|
| 58 | + { |
|
| 59 | + $_SESSION[$key] = $value; |
|
| 60 | + } |
|
| 61 | 61 | } |
| 62 | 62 | \ No newline at end of file |
@@ -10,26 +10,26 @@ discard block |
||
| 10 | 10 | { |
| 11 | 11 | private Server $server; |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @var string|array |
|
| 15 | - */ |
|
| 13 | + /** |
|
| 14 | + * @var string|array |
|
| 15 | + */ |
|
| 16 | 16 | private $requestBody; |
| 17 | 17 | |
| 18 | 18 | public function __construct(Server $server) |
| 19 | 19 | { |
| 20 | 20 | $this->server = $server; |
| 21 | 21 | $this->getBodyRequest(); |
| 22 | - $this->createProperty(); |
|
| 22 | + $this->createProperty(); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | private function getBodyRequest() |
| 26 | 26 | { |
| 27 | - $xml = new XML(); |
|
| 28 | - $json = new Json(); |
|
| 29 | - $post = new Post(); |
|
| 30 | - $formData = new FormData(); |
|
| 31 | - $urlEncode = new FormUrlEncoded(); |
|
| 32 | - $textPlain = new TextPlain(); |
|
| 27 | + $xml = new XML(); |
|
| 28 | + $json = new Json(); |
|
| 29 | + $post = new Post(); |
|
| 30 | + $formData = new FormData(); |
|
| 31 | + $urlEncode = new FormUrlEncoded(); |
|
| 32 | + $textPlain = new TextPlain(); |
|
| 33 | 33 | |
| 34 | 34 | $json->next($formData); |
| 35 | 35 | $formData->next($urlEncode); |
@@ -42,62 +42,62 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | private function createProperty() |
| 44 | 44 | { |
| 45 | - if (is_array($this->requestBody)) { |
|
| 46 | - foreach ($this->requestBody as $key => $value) { |
|
| 47 | - $this->$key = $value; |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function add(string $key, $value): void |
|
| 53 | - { |
|
| 54 | - $this->requestBody[$key] = $value; |
|
| 55 | - |
|
| 56 | - $this->__set($key, $value); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function remove(string $key): void |
|
| 60 | - { |
|
| 61 | - unset($this->requestBody[$key]); |
|
| 62 | - |
|
| 63 | - unset($this->$key); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - public function get(string $key) |
|
| 67 | - { |
|
| 68 | - return $this->requestBody[$key]; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return array|string |
|
| 73 | - */ |
|
| 74 | - public function all() |
|
| 75 | - { |
|
| 76 | - return $this->requestBody; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - public function __set($name, $value) |
|
| 80 | - { |
|
| 81 | - $this->$name = $value; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - public function __get($name) |
|
| 85 | - { |
|
| 86 | - $this->$name; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function except(array $keys): array |
|
| 90 | - { |
|
| 91 | - return ArrayUtil::except($this->requestBody, $keys); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - public function only(array $keys): array |
|
| 95 | - { |
|
| 96 | - return ArrayUtil::only($this->requestBody, $keys); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - public function has(string $key): bool |
|
| 100 | - { |
|
| 101 | - return !empty($this->requestBody[$key]); |
|
| 102 | - } |
|
| 45 | + if (is_array($this->requestBody)) { |
|
| 46 | + foreach ($this->requestBody as $key => $value) { |
|
| 47 | + $this->$key = $value; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public function add(string $key, $value): void |
|
| 53 | + { |
|
| 54 | + $this->requestBody[$key] = $value; |
|
| 55 | + |
|
| 56 | + $this->__set($key, $value); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function remove(string $key): void |
|
| 60 | + { |
|
| 61 | + unset($this->requestBody[$key]); |
|
| 62 | + |
|
| 63 | + unset($this->$key); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + public function get(string $key) |
|
| 67 | + { |
|
| 68 | + return $this->requestBody[$key]; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return array|string |
|
| 73 | + */ |
|
| 74 | + public function all() |
|
| 75 | + { |
|
| 76 | + return $this->requestBody; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + public function __set($name, $value) |
|
| 80 | + { |
|
| 81 | + $this->$name = $value; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + public function __get($name) |
|
| 85 | + { |
|
| 86 | + $this->$name; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function except(array $keys): array |
|
| 90 | + { |
|
| 91 | + return ArrayUtil::except($this->requestBody, $keys); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + public function only(array $keys): array |
|
| 95 | + { |
|
| 96 | + return ArrayUtil::only($this->requestBody, $keys); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + public function has(string $key): bool |
|
| 100 | + { |
|
| 101 | + return !empty($this->requestBody[$key]); |
|
| 102 | + } |
|
| 103 | 103 | } |
| 104 | 104 | \ No newline at end of file |
@@ -18,506 +18,506 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Request |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @var Cookie |
|
| 23 | - */ |
|
| 24 | - private Cookie $cookie; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var Env |
|
| 28 | - */ |
|
| 29 | - private Env $env; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var File |
|
| 33 | - */ |
|
| 34 | - private File $file; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var Get |
|
| 38 | - */ |
|
| 39 | - private Get $get; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var Server |
|
| 43 | - */ |
|
| 44 | - private Server $server; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var Session |
|
| 48 | - */ |
|
| 49 | - private Session $session; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var Content |
|
| 53 | - */ |
|
| 54 | - private Content $content; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Request constructor. |
|
| 58 | - */ |
|
| 59 | - public function __construct() |
|
| 60 | - { |
|
| 61 | - $this->cookie = new Cookie(); |
|
| 62 | - $this->env = new Env(); |
|
| 63 | - $this->file = new File(); |
|
| 64 | - $this->get = new Get(); |
|
| 65 | - $this->server = new Server(); |
|
| 66 | - $this->session = new Session(); |
|
| 67 | - $this->content = new Content($this->server); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @param string $key |
|
| 72 | - * @param $value |
|
| 73 | - */ |
|
| 74 | - public function addCookie(string $key, $value, $expire = 0, $path = "", $domain = "", $secure = false, $httponly = false): void |
|
| 75 | - { |
|
| 76 | - $this->cookie->add($key, $value, $expire, $path, $domain, $secure, $httponly); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param string|null $key |
|
| 81 | - * @return array|mixed |
|
| 82 | - */ |
|
| 83 | - public function cookies(?string $key = null) |
|
| 84 | - { |
|
| 85 | - if ($key) { |
|
| 86 | - return $this->cookie->get($key); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - return $this->cookie->all(); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param $key |
|
| 94 | - * @return bool |
|
| 95 | - */ |
|
| 96 | - public function hasCookie($key): bool |
|
| 97 | - { |
|
| 98 | - return $this->cookie->has($key); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param $key |
|
| 103 | - */ |
|
| 104 | - public function removeCookie($key): void |
|
| 105 | - { |
|
| 106 | - $this->cookie->remove($key); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @param array $values |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - public function exceptCookie(array $values): array |
|
| 114 | - { |
|
| 115 | - return $this->cookie->except($values); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @param array $values |
|
| 120 | - * @return array |
|
| 121 | - */ |
|
| 122 | - public function onlyCookie(array $values): array |
|
| 123 | - { |
|
| 124 | - return $this->cookie->only($values); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @param string|null $key |
|
| 129 | - * @return array|mixed |
|
| 130 | - */ |
|
| 131 | - public function query(?string $key = null) |
|
| 132 | - { |
|
| 133 | - if ($key) { |
|
| 134 | - return $this->get->get($key); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return $this->get->all(); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param string $key |
|
| 142 | - * @param $value |
|
| 143 | - */ |
|
| 144 | - public function addQuery(string $key, $value): void |
|
| 145 | - { |
|
| 146 | - $this->get->add($key, $value); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param array $values |
|
| 151 | - * @return array |
|
| 152 | - */ |
|
| 153 | - public function onlyQuery(array $values): array |
|
| 154 | - { |
|
| 155 | - return $this->get->only($values); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @param array $values |
|
| 160 | - * @return array |
|
| 161 | - */ |
|
| 162 | - public function exceptQuery(array $values): array |
|
| 163 | - { |
|
| 164 | - return $this->get->except($values); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @param string $value |
|
| 169 | - * @return bool |
|
| 170 | - */ |
|
| 171 | - public function hasQuery(string $value): bool |
|
| 172 | - { |
|
| 173 | - return $this->get->has($value); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param string $key |
|
| 178 | - */ |
|
| 179 | - public function removeQuery(string $key): void |
|
| 180 | - { |
|
| 181 | - $this->get->remove($key); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @param string|null $key |
|
| 186 | - * @return array|mixed |
|
| 187 | - */ |
|
| 188 | - public function env(?string $key = null) |
|
| 189 | - { |
|
| 190 | - if ($key) { |
|
| 191 | - return $this->env->get($key); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $this->env->all(); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @param string $key |
|
| 199 | - * @param $value |
|
| 200 | - */ |
|
| 201 | - public function addEnv(string $key, $value): void |
|
| 202 | - { |
|
| 203 | - $this->env->add($key, $value); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * @param array $values |
|
| 208 | - * @return array |
|
| 209 | - */ |
|
| 210 | - public function onlyEnv(array $values): array |
|
| 211 | - { |
|
| 212 | - return $this->env->only($values); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @param array $values |
|
| 217 | - * @return array |
|
| 218 | - */ |
|
| 219 | - public function exceptEnv(array $values): array |
|
| 220 | - { |
|
| 221 | - return $this->env->except($values); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @param string $value |
|
| 226 | - * @return bool |
|
| 227 | - */ |
|
| 228 | - public function hasEnv(string $value): bool |
|
| 229 | - { |
|
| 230 | - return $this->env->has($value); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * @param string $key |
|
| 235 | - */ |
|
| 236 | - public function removeEnv(string $key): void |
|
| 237 | - { |
|
| 238 | - $this->env->remove($key); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * @param string|null $key |
|
| 243 | - * @return array |
|
| 244 | - */ |
|
| 245 | - public function file(?string $key = null) |
|
| 246 | - { |
|
| 247 | - if ($key) { |
|
| 248 | - return $this->file->get($key); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - return $this->file->all(); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @param $key |
|
| 256 | - * @return bool |
|
| 257 | - */ |
|
| 258 | - public function hasFile($key): bool |
|
| 259 | - { |
|
| 260 | - return $this->file->has($key); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * @param $key |
|
| 265 | - */ |
|
| 266 | - public function removeFile($key): void |
|
| 267 | - { |
|
| 268 | - $this->file->remove($key); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * @param array $values |
|
| 273 | - * @return array |
|
| 274 | - */ |
|
| 275 | - public function exceptFile(array $values): array |
|
| 276 | - { |
|
| 277 | - return $this->file->except($values); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * @param array $values |
|
| 282 | - * @return array |
|
| 283 | - */ |
|
| 284 | - public function onlyFile(array $values): array |
|
| 285 | - { |
|
| 286 | - return $this->file->only($values); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * @param string $key |
|
| 291 | - * @param $value |
|
| 292 | - */ |
|
| 293 | - public function addHeader(string $key, $value): void |
|
| 294 | - { |
|
| 295 | - $this->server->add($key, $value); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * @param string $key |
|
| 300 | - * @return array|mixed |
|
| 301 | - */ |
|
| 302 | - public function header(string $key) |
|
| 303 | - { |
|
| 304 | - return $this->server->get($key); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * @param $key |
|
| 309 | - * @return bool |
|
| 310 | - */ |
|
| 311 | - public function hasheader($key): bool |
|
| 312 | - { |
|
| 313 | - return $this->server->has($key); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * @param $key |
|
| 318 | - */ |
|
| 319 | - public function removeHeader($key): void |
|
| 320 | - { |
|
| 321 | - $this->server->remove($key); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * @param array $values |
|
| 326 | - * @return array |
|
| 327 | - */ |
|
| 328 | - public function exceptHeaders(array $values): array |
|
| 329 | - { |
|
| 330 | - return $this->server->except($values); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * @param array $values |
|
| 335 | - * @return array |
|
| 336 | - */ |
|
| 337 | - public function onlyHeaders(array $values): array |
|
| 338 | - { |
|
| 339 | - return $this->server->only($values); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * @return string |
|
| 344 | - */ |
|
| 345 | - public function method(): string |
|
| 346 | - { |
|
| 347 | - return $this->server->method(); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * @return string |
|
| 352 | - */ |
|
| 353 | - public function getUrl(): string |
|
| 354 | - { |
|
| 355 | - return $this->server->getUrl(); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * @param string $method |
|
| 360 | - * @return bool |
|
| 361 | - */ |
|
| 362 | - public function isMethod(string $method): bool |
|
| 363 | - { |
|
| 364 | - return $this->method() === strtoupper($method); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * @return array |
|
| 369 | - */ |
|
| 370 | - public function headers(): array |
|
| 371 | - { |
|
| 372 | - return $this->server->all(); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * @param string $path |
|
| 377 | - * @param int $code |
|
| 378 | - * @return bool |
|
| 379 | - */ |
|
| 380 | - public function redirect(string $path, int $code = 301) |
|
| 381 | - { |
|
| 382 | - header("HTTP/1.0 {$code}"); |
|
| 383 | - header("Location: {$path}"); |
|
| 384 | - |
|
| 385 | - return true; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * @param string $key |
|
| 390 | - * @param $value |
|
| 391 | - */ |
|
| 392 | - public function addSession(string $key, $value): void |
|
| 393 | - { |
|
| 394 | - $this->session->add($key, $value); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * @param string|null $key |
|
| 399 | - * @return array|mixed |
|
| 400 | - */ |
|
| 401 | - public function session(?string $key = null) |
|
| 402 | - { |
|
| 403 | - if ($key) { |
|
| 404 | - return $this->session->get($key); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - return $this->session->all(); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * @param $key |
|
| 412 | - * @return bool |
|
| 413 | - */ |
|
| 414 | - public function hasSession($key): bool |
|
| 415 | - { |
|
| 416 | - return $this->session->has($key); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * @param $key |
|
| 421 | - */ |
|
| 422 | - public function removeSession($key): void |
|
| 423 | - { |
|
| 424 | - $this->session->remove($key); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * @param array $values |
|
| 429 | - * @return array |
|
| 430 | - */ |
|
| 431 | - public function exceptSession(array $values): array |
|
| 432 | - { |
|
| 433 | - return $this->session->except($values); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * @param array $values |
|
| 438 | - * @return array |
|
| 439 | - */ |
|
| 440 | - public function onlySession(array $values): array |
|
| 441 | - { |
|
| 442 | - return $this->session->only($values); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * @param array $values |
|
| 447 | - * @return array |
|
| 448 | - */ |
|
| 449 | - public function except(array $values) |
|
| 450 | - { |
|
| 451 | - return $this->content->except($values); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * @param array $values |
|
| 456 | - * @return array |
|
| 457 | - */ |
|
| 458 | - public function only(array $values) |
|
| 459 | - { |
|
| 460 | - return $this->content->only($values); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * @param string $key |
|
| 465 | - * @return bool |
|
| 466 | - */ |
|
| 467 | - public function has(string $key): bool |
|
| 468 | - { |
|
| 469 | - return $this->content->has($key); |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * @param string $key |
|
| 474 | - */ |
|
| 475 | - public function remove(string $key): void |
|
| 476 | - { |
|
| 477 | - $this->content->remove($key); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * @param $key |
|
| 482 | - * @param $value |
|
| 483 | - */ |
|
| 484 | - public function add($key, $value) |
|
| 485 | - { |
|
| 486 | - $this->content->add($key, $value); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * @return array |
|
| 491 | - */ |
|
| 492 | - public function all(): array |
|
| 493 | - { |
|
| 494 | - return $this->content->all(); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * Return all body data as stdClass object |
|
| 499 | - * |
|
| 500 | - * @return stdClass |
|
| 501 | - */ |
|
| 502 | - public function bodyAsObject(): stdClass |
|
| 503 | - { |
|
| 504 | - return ArrayUtil::converToObject($this->content->all()); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * @param string $value |
|
| 509 | - * @return mixed |
|
| 510 | - */ |
|
| 511 | - public function get(string $value) |
|
| 512 | - { |
|
| 513 | - return $this->content->get($value); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * @param $name |
|
| 518 | - */ |
|
| 519 | - public function __get($name) |
|
| 520 | - { |
|
| 521 | - return $this->content->$name; |
|
| 522 | - } |
|
| 21 | + /** |
|
| 22 | + * @var Cookie |
|
| 23 | + */ |
|
| 24 | + private Cookie $cookie; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var Env |
|
| 28 | + */ |
|
| 29 | + private Env $env; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var File |
|
| 33 | + */ |
|
| 34 | + private File $file; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var Get |
|
| 38 | + */ |
|
| 39 | + private Get $get; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var Server |
|
| 43 | + */ |
|
| 44 | + private Server $server; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var Session |
|
| 48 | + */ |
|
| 49 | + private Session $session; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var Content |
|
| 53 | + */ |
|
| 54 | + private Content $content; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Request constructor. |
|
| 58 | + */ |
|
| 59 | + public function __construct() |
|
| 60 | + { |
|
| 61 | + $this->cookie = new Cookie(); |
|
| 62 | + $this->env = new Env(); |
|
| 63 | + $this->file = new File(); |
|
| 64 | + $this->get = new Get(); |
|
| 65 | + $this->server = new Server(); |
|
| 66 | + $this->session = new Session(); |
|
| 67 | + $this->content = new Content($this->server); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @param string $key |
|
| 72 | + * @param $value |
|
| 73 | + */ |
|
| 74 | + public function addCookie(string $key, $value, $expire = 0, $path = "", $domain = "", $secure = false, $httponly = false): void |
|
| 75 | + { |
|
| 76 | + $this->cookie->add($key, $value, $expire, $path, $domain, $secure, $httponly); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param string|null $key |
|
| 81 | + * @return array|mixed |
|
| 82 | + */ |
|
| 83 | + public function cookies(?string $key = null) |
|
| 84 | + { |
|
| 85 | + if ($key) { |
|
| 86 | + return $this->cookie->get($key); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + return $this->cookie->all(); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param $key |
|
| 94 | + * @return bool |
|
| 95 | + */ |
|
| 96 | + public function hasCookie($key): bool |
|
| 97 | + { |
|
| 98 | + return $this->cookie->has($key); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param $key |
|
| 103 | + */ |
|
| 104 | + public function removeCookie($key): void |
|
| 105 | + { |
|
| 106 | + $this->cookie->remove($key); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @param array $values |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + public function exceptCookie(array $values): array |
|
| 114 | + { |
|
| 115 | + return $this->cookie->except($values); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @param array $values |
|
| 120 | + * @return array |
|
| 121 | + */ |
|
| 122 | + public function onlyCookie(array $values): array |
|
| 123 | + { |
|
| 124 | + return $this->cookie->only($values); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @param string|null $key |
|
| 129 | + * @return array|mixed |
|
| 130 | + */ |
|
| 131 | + public function query(?string $key = null) |
|
| 132 | + { |
|
| 133 | + if ($key) { |
|
| 134 | + return $this->get->get($key); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return $this->get->all(); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param string $key |
|
| 142 | + * @param $value |
|
| 143 | + */ |
|
| 144 | + public function addQuery(string $key, $value): void |
|
| 145 | + { |
|
| 146 | + $this->get->add($key, $value); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @param array $values |
|
| 151 | + * @return array |
|
| 152 | + */ |
|
| 153 | + public function onlyQuery(array $values): array |
|
| 154 | + { |
|
| 155 | + return $this->get->only($values); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @param array $values |
|
| 160 | + * @return array |
|
| 161 | + */ |
|
| 162 | + public function exceptQuery(array $values): array |
|
| 163 | + { |
|
| 164 | + return $this->get->except($values); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @param string $value |
|
| 169 | + * @return bool |
|
| 170 | + */ |
|
| 171 | + public function hasQuery(string $value): bool |
|
| 172 | + { |
|
| 173 | + return $this->get->has($value); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param string $key |
|
| 178 | + */ |
|
| 179 | + public function removeQuery(string $key): void |
|
| 180 | + { |
|
| 181 | + $this->get->remove($key); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @param string|null $key |
|
| 186 | + * @return array|mixed |
|
| 187 | + */ |
|
| 188 | + public function env(?string $key = null) |
|
| 189 | + { |
|
| 190 | + if ($key) { |
|
| 191 | + return $this->env->get($key); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $this->env->all(); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @param string $key |
|
| 199 | + * @param $value |
|
| 200 | + */ |
|
| 201 | + public function addEnv(string $key, $value): void |
|
| 202 | + { |
|
| 203 | + $this->env->add($key, $value); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * @param array $values |
|
| 208 | + * @return array |
|
| 209 | + */ |
|
| 210 | + public function onlyEnv(array $values): array |
|
| 211 | + { |
|
| 212 | + return $this->env->only($values); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @param array $values |
|
| 217 | + * @return array |
|
| 218 | + */ |
|
| 219 | + public function exceptEnv(array $values): array |
|
| 220 | + { |
|
| 221 | + return $this->env->except($values); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @param string $value |
|
| 226 | + * @return bool |
|
| 227 | + */ |
|
| 228 | + public function hasEnv(string $value): bool |
|
| 229 | + { |
|
| 230 | + return $this->env->has($value); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * @param string $key |
|
| 235 | + */ |
|
| 236 | + public function removeEnv(string $key): void |
|
| 237 | + { |
|
| 238 | + $this->env->remove($key); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * @param string|null $key |
|
| 243 | + * @return array |
|
| 244 | + */ |
|
| 245 | + public function file(?string $key = null) |
|
| 246 | + { |
|
| 247 | + if ($key) { |
|
| 248 | + return $this->file->get($key); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + return $this->file->all(); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @param $key |
|
| 256 | + * @return bool |
|
| 257 | + */ |
|
| 258 | + public function hasFile($key): bool |
|
| 259 | + { |
|
| 260 | + return $this->file->has($key); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * @param $key |
|
| 265 | + */ |
|
| 266 | + public function removeFile($key): void |
|
| 267 | + { |
|
| 268 | + $this->file->remove($key); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * @param array $values |
|
| 273 | + * @return array |
|
| 274 | + */ |
|
| 275 | + public function exceptFile(array $values): array |
|
| 276 | + { |
|
| 277 | + return $this->file->except($values); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * @param array $values |
|
| 282 | + * @return array |
|
| 283 | + */ |
|
| 284 | + public function onlyFile(array $values): array |
|
| 285 | + { |
|
| 286 | + return $this->file->only($values); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * @param string $key |
|
| 291 | + * @param $value |
|
| 292 | + */ |
|
| 293 | + public function addHeader(string $key, $value): void |
|
| 294 | + { |
|
| 295 | + $this->server->add($key, $value); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * @param string $key |
|
| 300 | + * @return array|mixed |
|
| 301 | + */ |
|
| 302 | + public function header(string $key) |
|
| 303 | + { |
|
| 304 | + return $this->server->get($key); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * @param $key |
|
| 309 | + * @return bool |
|
| 310 | + */ |
|
| 311 | + public function hasheader($key): bool |
|
| 312 | + { |
|
| 313 | + return $this->server->has($key); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * @param $key |
|
| 318 | + */ |
|
| 319 | + public function removeHeader($key): void |
|
| 320 | + { |
|
| 321 | + $this->server->remove($key); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * @param array $values |
|
| 326 | + * @return array |
|
| 327 | + */ |
|
| 328 | + public function exceptHeaders(array $values): array |
|
| 329 | + { |
|
| 330 | + return $this->server->except($values); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * @param array $values |
|
| 335 | + * @return array |
|
| 336 | + */ |
|
| 337 | + public function onlyHeaders(array $values): array |
|
| 338 | + { |
|
| 339 | + return $this->server->only($values); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * @return string |
|
| 344 | + */ |
|
| 345 | + public function method(): string |
|
| 346 | + { |
|
| 347 | + return $this->server->method(); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * @return string |
|
| 352 | + */ |
|
| 353 | + public function getUrl(): string |
|
| 354 | + { |
|
| 355 | + return $this->server->getUrl(); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * @param string $method |
|
| 360 | + * @return bool |
|
| 361 | + */ |
|
| 362 | + public function isMethod(string $method): bool |
|
| 363 | + { |
|
| 364 | + return $this->method() === strtoupper($method); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * @return array |
|
| 369 | + */ |
|
| 370 | + public function headers(): array |
|
| 371 | + { |
|
| 372 | + return $this->server->all(); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * @param string $path |
|
| 377 | + * @param int $code |
|
| 378 | + * @return bool |
|
| 379 | + */ |
|
| 380 | + public function redirect(string $path, int $code = 301) |
|
| 381 | + { |
|
| 382 | + header("HTTP/1.0 {$code}"); |
|
| 383 | + header("Location: {$path}"); |
|
| 384 | + |
|
| 385 | + return true; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * @param string $key |
|
| 390 | + * @param $value |
|
| 391 | + */ |
|
| 392 | + public function addSession(string $key, $value): void |
|
| 393 | + { |
|
| 394 | + $this->session->add($key, $value); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * @param string|null $key |
|
| 399 | + * @return array|mixed |
|
| 400 | + */ |
|
| 401 | + public function session(?string $key = null) |
|
| 402 | + { |
|
| 403 | + if ($key) { |
|
| 404 | + return $this->session->get($key); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + return $this->session->all(); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * @param $key |
|
| 412 | + * @return bool |
|
| 413 | + */ |
|
| 414 | + public function hasSession($key): bool |
|
| 415 | + { |
|
| 416 | + return $this->session->has($key); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * @param $key |
|
| 421 | + */ |
|
| 422 | + public function removeSession($key): void |
|
| 423 | + { |
|
| 424 | + $this->session->remove($key); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * @param array $values |
|
| 429 | + * @return array |
|
| 430 | + */ |
|
| 431 | + public function exceptSession(array $values): array |
|
| 432 | + { |
|
| 433 | + return $this->session->except($values); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * @param array $values |
|
| 438 | + * @return array |
|
| 439 | + */ |
|
| 440 | + public function onlySession(array $values): array |
|
| 441 | + { |
|
| 442 | + return $this->session->only($values); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * @param array $values |
|
| 447 | + * @return array |
|
| 448 | + */ |
|
| 449 | + public function except(array $values) |
|
| 450 | + { |
|
| 451 | + return $this->content->except($values); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * @param array $values |
|
| 456 | + * @return array |
|
| 457 | + */ |
|
| 458 | + public function only(array $values) |
|
| 459 | + { |
|
| 460 | + return $this->content->only($values); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * @param string $key |
|
| 465 | + * @return bool |
|
| 466 | + */ |
|
| 467 | + public function has(string $key): bool |
|
| 468 | + { |
|
| 469 | + return $this->content->has($key); |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * @param string $key |
|
| 474 | + */ |
|
| 475 | + public function remove(string $key): void |
|
| 476 | + { |
|
| 477 | + $this->content->remove($key); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * @param $key |
|
| 482 | + * @param $value |
|
| 483 | + */ |
|
| 484 | + public function add($key, $value) |
|
| 485 | + { |
|
| 486 | + $this->content->add($key, $value); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * @return array |
|
| 491 | + */ |
|
| 492 | + public function all(): array |
|
| 493 | + { |
|
| 494 | + return $this->content->all(); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * Return all body data as stdClass object |
|
| 499 | + * |
|
| 500 | + * @return stdClass |
|
| 501 | + */ |
|
| 502 | + public function bodyAsObject(): stdClass |
|
| 503 | + { |
|
| 504 | + return ArrayUtil::converToObject($this->content->all()); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * @param string $value |
|
| 509 | + * @return mixed |
|
| 510 | + */ |
|
| 511 | + public function get(string $value) |
|
| 512 | + { |
|
| 513 | + return $this->content->get($value); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * @param $name |
|
| 518 | + */ |
|
| 519 | + public function __get($name) |
|
| 520 | + { |
|
| 521 | + return $this->content->$name; |
|
| 522 | + } |
|
| 523 | 523 | } |
| 524 | 524 | \ No newline at end of file |
@@ -8,32 +8,32 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | class Response |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @var array |
|
| 13 | - */ |
|
| 14 | - private array $headers; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * @var int |
|
| 18 | - */ |
|
| 19 | - private int $statusCode; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Response constructor. |
|
| 23 | - */ |
|
| 24 | - public function __construct() |
|
| 25 | - { |
|
| 26 | - $this->headers = []; |
|
| 27 | - $this->statusCode = 200; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Added several headers. |
|
| 32 | - * |
|
| 33 | - * @param array $headers |
|
| 34 | - * @return $this |
|
| 35 | - */ |
|
| 36 | - public function addHeaders(array $headers): Response |
|
| 11 | + /** |
|
| 12 | + * @var array |
|
| 13 | + */ |
|
| 14 | + private array $headers; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * @var int |
|
| 18 | + */ |
|
| 19 | + private int $statusCode; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Response constructor. |
|
| 23 | + */ |
|
| 24 | + public function __construct() |
|
| 25 | + { |
|
| 26 | + $this->headers = []; |
|
| 27 | + $this->statusCode = 200; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Added several headers. |
|
| 32 | + * |
|
| 33 | + * @param array $headers |
|
| 34 | + * @return $this |
|
| 35 | + */ |
|
| 36 | + public function addHeaders(array $headers): Response |
|
| 37 | 37 | { |
| 38 | 38 | foreach ($headers as $v) { |
| 39 | 39 | $this->headers[] = $v; |
@@ -42,58 +42,58 @@ discard block |
||
| 42 | 42 | return $this; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Added a header. |
|
| 47 | - * |
|
| 48 | - * @param string $header |
|
| 49 | - * @param mixed $value |
|
| 50 | - * @return $this |
|
| 51 | - */ |
|
| 52 | - public function addHeader(string $header, $value): Response |
|
| 45 | + /** |
|
| 46 | + * Added a header. |
|
| 47 | + * |
|
| 48 | + * @param string $header |
|
| 49 | + * @param mixed $value |
|
| 50 | + * @return $this |
|
| 51 | + */ |
|
| 52 | + public function addHeader(string $header, $value): Response |
|
| 53 | 53 | { |
| 54 | - $this->headers[$header] = $value; |
|
| 54 | + $this->headers[$header] = $value; |
|
| 55 | 55 | |
| 56 | 56 | return $this; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Returns the defined headers. |
|
| 61 | - * @return array |
|
| 62 | - */ |
|
| 63 | - public function getHeaders(): array |
|
| 59 | + /** |
|
| 60 | + * Returns the defined headers. |
|
| 61 | + * @return array |
|
| 62 | + */ |
|
| 63 | + public function getHeaders(): array |
|
| 64 | 64 | { |
| 65 | 65 | return $this->headers; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Set status code. |
|
| 70 | - * |
|
| 71 | - * @param int $statusCode |
|
| 72 | - * @return $this |
|
| 73 | - */ |
|
| 74 | - public function setStatusCode(int $statusCode): Response |
|
| 68 | + /** |
|
| 69 | + * Set status code. |
|
| 70 | + * |
|
| 71 | + * @param int $statusCode |
|
| 72 | + * @return $this |
|
| 73 | + */ |
|
| 74 | + public function setStatusCode(int $statusCode): Response |
|
| 75 | 75 | { |
| 76 | 76 | $this->statusCode = $statusCode; |
| 77 | 77 | |
| 78 | 78 | return $this; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Returns the defined status code. |
|
| 83 | - * |
|
| 84 | - * @return int |
|
| 85 | - */ |
|
| 86 | - public function getStatusCode(): int |
|
| 81 | + /** |
|
| 82 | + * Returns the defined status code. |
|
| 83 | + * |
|
| 84 | + * @return int |
|
| 85 | + */ |
|
| 86 | + public function getStatusCode(): int |
|
| 87 | 87 | { |
| 88 | 88 | return $this->statusCode; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Set all headers. |
|
| 93 | - * |
|
| 94 | - * @return $this |
|
| 95 | - */ |
|
| 96 | - public function response(): Response |
|
| 91 | + /** |
|
| 92 | + * Set all headers. |
|
| 93 | + * |
|
| 94 | + * @return $this |
|
| 95 | + */ |
|
| 96 | + public function response(): Response |
|
| 97 | 97 | { |
| 98 | 98 | foreach ($this->headers as $k => $v) { |
| 99 | 99 | header("{$v}"); |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | return $this; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Return a json and set the header to application/json. |
|
| 109 | - * |
|
| 110 | - * @param array $data |
|
| 111 | - * @return false|string |
|
| 112 | - */ |
|
| 113 | - public function json(array $data) |
|
| 107 | + /** |
|
| 108 | + * Return a json and set the header to application/json. |
|
| 109 | + * |
|
| 110 | + * @param array $data |
|
| 111 | + * @return false|string |
|
| 112 | + */ |
|
| 113 | + public function json(array $data) |
|
| 114 | 114 | { |
| 115 | 115 | header("Content-type: application/json"); |
| 116 | 116 | |