@@ -6,39 +6,39 @@ |
||
6 | 6 | |
7 | 7 | class XML implements Handler, Advancer |
8 | 8 | { |
9 | - private Handler $handler; |
|
10 | - |
|
11 | - public function getBody($content) |
|
12 | - { |
|
13 | - $xml = simplexml_load_string($content); |
|
14 | - $json = json_encode($xml); |
|
15 | - return json_decode($json, true); |
|
16 | - } |
|
17 | - |
|
18 | - public function next(Handler $handler) |
|
19 | - { |
|
20 | - $this->handler = $handler; |
|
21 | - } |
|
22 | - |
|
23 | - private function isTextXml($server): bool |
|
24 | - { |
|
25 | - return ContentHelper::contentIs($server, 'text/xml'); |
|
26 | - } |
|
27 | - |
|
28 | - private function isApplicationXml($server): bool |
|
29 | - { |
|
30 | - return ContentHelper::contentIs($server, 'application/xml'); |
|
31 | - } |
|
32 | - |
|
33 | - public function handle($server) |
|
34 | - { |
|
35 | - $isTextXML = $this->isTextXml($server); |
|
36 | - $isApplicationXML = $this->isApplicationXml($server); |
|
37 | - |
|
38 | - if ($isTextXML || $isApplicationXML) { |
|
39 | - return $this->getBody($server->getContent()); |
|
40 | - } |
|
41 | - |
|
42 | - return $this->handler->handle($server); |
|
43 | - } |
|
9 | + private Handler $handler; |
|
10 | + |
|
11 | + public function getBody($content) |
|
12 | + { |
|
13 | + $xml = simplexml_load_string($content); |
|
14 | + $json = json_encode($xml); |
|
15 | + return json_decode($json, true); |
|
16 | + } |
|
17 | + |
|
18 | + public function next(Handler $handler) |
|
19 | + { |
|
20 | + $this->handler = $handler; |
|
21 | + } |
|
22 | + |
|
23 | + private function isTextXml($server): bool |
|
24 | + { |
|
25 | + return ContentHelper::contentIs($server, 'text/xml'); |
|
26 | + } |
|
27 | + |
|
28 | + private function isApplicationXml($server): bool |
|
29 | + { |
|
30 | + return ContentHelper::contentIs($server, 'application/xml'); |
|
31 | + } |
|
32 | + |
|
33 | + public function handle($server) |
|
34 | + { |
|
35 | + $isTextXML = $this->isTextXml($server); |
|
36 | + $isApplicationXML = $this->isApplicationXml($server); |
|
37 | + |
|
38 | + if ($isTextXML || $isApplicationXML) { |
|
39 | + return $this->getBody($server->getContent()); |
|
40 | + } |
|
41 | + |
|
42 | + return $this->handler->handle($server); |
|
43 | + } |
|
44 | 44 | } |
45 | 45 | \ No newline at end of file |
@@ -6,24 +6,24 @@ |
||
6 | 6 | |
7 | 7 | class TextPlain implements Handler, Advancer |
8 | 8 | { |
9 | - private Handler $handler; |
|
9 | + private Handler $handler; |
|
10 | 10 | |
11 | - public function getBody($content) |
|
12 | - { |
|
13 | - return [$content]; |
|
14 | - } |
|
11 | + public function getBody($content) |
|
12 | + { |
|
13 | + return [$content]; |
|
14 | + } |
|
15 | 15 | |
16 | - public function next(Handler $handler) |
|
17 | - { |
|
18 | - $this->handler = $handler; |
|
19 | - } |
|
16 | + public function next(Handler $handler) |
|
17 | + { |
|
18 | + $this->handler = $handler; |
|
19 | + } |
|
20 | 20 | |
21 | - public function handle($server) |
|
22 | - { |
|
23 | - if (ContentHelper::contentIs($server, 'text/plain')) { |
|
24 | - return $this->getBody($server->getContent()); |
|
25 | - } |
|
21 | + public function handle($server) |
|
22 | + { |
|
23 | + if (ContentHelper::contentIs($server, 'text/plain')) { |
|
24 | + return $this->getBody($server->getContent()); |
|
25 | + } |
|
26 | 26 | |
27 | - return $this->handler->handle($server); |
|
28 | - } |
|
27 | + return $this->handler->handle($server); |
|
28 | + } |
|
29 | 29 | } |
30 | 30 | \ No newline at end of file |
@@ -10,9 +10,9 @@ 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 $body; |
17 | 17 | |
18 | 18 | public function __construct(Server $server) |
@@ -24,12 +24,12 @@ discard block |
||
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->body)) { |
|
46 | - foreach ($this->body as $key => $value) { |
|
47 | - $this->__set($key, $value); |
|
48 | - } |
|
49 | - } |
|
45 | + if (is_array($this->body)) { |
|
46 | + foreach ($this->body as $key => $value) { |
|
47 | + $this->__set($key, $value); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | } |
51 | 51 | |
52 | - public function add(string $key, $value): void |
|
53 | - { |
|
54 | - $this->body[$key] = $value; |
|
55 | - |
|
56 | - $this->__set($key, $value); |
|
57 | - } |
|
58 | - |
|
59 | - public function remove(string $key): void |
|
60 | - { |
|
61 | - unset($this->body[$key]); |
|
62 | - |
|
63 | - unset($this->$key); |
|
64 | - } |
|
65 | - |
|
66 | - public function get(string $key) |
|
67 | - { |
|
68 | - return $this->body[$key]; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @return array|string |
|
73 | - */ |
|
74 | - public function all() |
|
75 | - { |
|
76 | - return $this->body; |
|
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->body, $keys); |
|
92 | - } |
|
93 | - |
|
94 | - public function only(array $keys): array |
|
95 | - { |
|
96 | - return ArrayUtil::only($this->body, $keys); |
|
97 | - } |
|
98 | - |
|
99 | - public function has(string $key): bool |
|
100 | - { |
|
101 | - return !empty($this->body[$key]); |
|
102 | - } |
|
52 | + public function add(string $key, $value): void |
|
53 | + { |
|
54 | + $this->body[$key] = $value; |
|
55 | + |
|
56 | + $this->__set($key, $value); |
|
57 | + } |
|
58 | + |
|
59 | + public function remove(string $key): void |
|
60 | + { |
|
61 | + unset($this->body[$key]); |
|
62 | + |
|
63 | + unset($this->$key); |
|
64 | + } |
|
65 | + |
|
66 | + public function get(string $key) |
|
67 | + { |
|
68 | + return $this->body[$key]; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @return array|string |
|
73 | + */ |
|
74 | + public function all() |
|
75 | + { |
|
76 | + return $this->body; |
|
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->body, $keys); |
|
92 | + } |
|
93 | + |
|
94 | + public function only(array $keys): array |
|
95 | + { |
|
96 | + return ArrayUtil::only($this->body, $keys); |
|
97 | + } |
|
98 | + |
|
99 | + public function has(string $key): bool |
|
100 | + { |
|
101 | + return !empty($this->body[$key]); |
|
102 | + } |
|
103 | 103 | } |
104 | 104 | \ No newline at end of file |
@@ -10,19 +10,19 @@ |
||
10 | 10 | |
11 | 11 | public function getBody($content) |
12 | 12 | { |
13 | - if (is_array($content)) { |
|
14 | - return $content; |
|
15 | - } |
|
13 | + if (is_array($content)) { |
|
14 | + return $content; |
|
15 | + } |
|
16 | 16 | |
17 | - $body = explode('&', $content); |
|
18 | - $data = []; |
|
17 | + $body = explode('&', $content); |
|
18 | + $data = []; |
|
19 | 19 | |
20 | - foreach ($body as $parameter) { |
|
21 | - $parameterParsed = explode('=', $parameter); |
|
22 | - $data[$parameterParsed[0]] = $parameterParsed[1]; |
|
23 | - } |
|
20 | + foreach ($body as $parameter) { |
|
21 | + $parameterParsed = explode('=', $parameter); |
|
22 | + $data[$parameterParsed[0]] = $parameterParsed[1]; |
|
23 | + } |
|
24 | 24 | |
25 | - return $data; |
|
25 | + return $data; |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | public function next(Handler $handler) |
@@ -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) |
@@ -16,15 +16,15 @@ discard block |
||
16 | 16 | private Server $server; |
17 | 17 | |
18 | 18 | public function __construct( |
19 | - Content $body, |
|
20 | - Get $get, |
|
21 | - File $file, |
|
22 | - Server $server |
|
19 | + Content $body, |
|
20 | + Get $get, |
|
21 | + File $file, |
|
22 | + Server $server |
|
23 | 23 | ) |
24 | 24 | { |
25 | - $this->body = $body->getBodyRequest(); |
|
26 | - $this->get = $get; |
|
27 | - $this->server = $server; |
|
25 | + $this->body = $body->getBodyRequest(); |
|
26 | + $this->get = $get; |
|
27 | + $this->server = $server; |
|
28 | 28 | $this->file = $file; |
29 | 29 | } |
30 | 30 | |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | public function bodyObject() |
37 | 37 | { |
38 | 38 | if (is_array($this->body)) { |
39 | - return ArrayUtil::converToObject($this->body); |
|
40 | - } |
|
39 | + return ArrayUtil::converToObject($this->body); |
|
40 | + } |
|
41 | 41 | |
42 | 42 | if (is_object($this->body)) { |
43 | - return $this->body; |
|
44 | - } |
|
43 | + return $this->body; |
|
44 | + } |
|
45 | 45 | |
46 | 46 | throw new \Exception("It wasn't possible convert to object"); |
47 | 47 | } |
@@ -24,8 +24,8 @@ |
||
24 | 24 | { |
25 | 25 | $this->body = $body->getBodyRequest(); |
26 | 26 | $this->get = $get; |
27 | - $this->server = $server; |
|
28 | - $this->file = $file; |
|
27 | + $this->server = $server; |
|
28 | + $this->file = $file; |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | public function all() |
@@ -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 |