@@ -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 |
@@ -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 | |
@@ -6,40 +6,40 @@ |
||
| 6 | 6 | |
| 7 | 7 | class XML implements Handler, Advancer |
| 8 | 8 | { |
| 9 | - private Handler $handler; |
|
| 10 | - |
|
| 11 | - public function getBody($content): array |
|
| 12 | - { |
|
| 13 | - $xml = simplexml_load_string($content); |
|
| 14 | - $json = json_encode($xml); |
|
| 15 | - |
|
| 16 | - return json_decode($json, true); |
|
| 17 | - } |
|
| 18 | - |
|
| 19 | - public function next(Handler $handler): void |
|
| 20 | - { |
|
| 21 | - $this->handler = $handler; |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - private function isTextXml($server): bool |
|
| 25 | - { |
|
| 26 | - return ContentHelper::contentIs($server, 'text/xml'); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - private function isApplicationXml($server): bool |
|
| 30 | - { |
|
| 31 | - return ContentHelper::contentIs($server, 'application/xml'); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public function handle($server): array |
|
| 35 | - { |
|
| 36 | - $isTextXML = $this->isTextXml($server); |
|
| 37 | - $isApplicationXML = $this->isApplicationXml($server); |
|
| 38 | - |
|
| 39 | - if ($isTextXML || $isApplicationXML) { |
|
| 40 | - return $this->getBody($server->getContent()); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - return $this->handler->handle($server); |
|
| 44 | - } |
|
| 9 | + private Handler $handler; |
|
| 10 | + |
|
| 11 | + public function getBody($content): array |
|
| 12 | + { |
|
| 13 | + $xml = simplexml_load_string($content); |
|
| 14 | + $json = json_encode($xml); |
|
| 15 | + |
|
| 16 | + return json_decode($json, true); |
|
| 17 | + } |
|
| 18 | + |
|
| 19 | + public function next(Handler $handler): void |
|
| 20 | + { |
|
| 21 | + $this->handler = $handler; |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + private function isTextXml($server): bool |
|
| 25 | + { |
|
| 26 | + return ContentHelper::contentIs($server, 'text/xml'); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + private function isApplicationXml($server): bool |
|
| 30 | + { |
|
| 31 | + return ContentHelper::contentIs($server, 'application/xml'); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + public function handle($server): array |
|
| 35 | + { |
|
| 36 | + $isTextXML = $this->isTextXml($server); |
|
| 37 | + $isApplicationXML = $this->isApplicationXml($server); |
|
| 38 | + |
|
| 39 | + if ($isTextXML || $isApplicationXML) { |
|
| 40 | + return $this->getBody($server->getContent()); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + return $this->handler->handle($server); |
|
| 44 | + } |
|
| 45 | 45 | } |
| 46 | 46 | \ No newline at end of file |