@@ -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): array |
|
| 12 | - { |
|
| 13 | - return [$content]; |
|
| 14 | - } |
|
| 11 | + public function getBody($content): array |
|
| 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): array |
|
| 22 | - { |
|
| 23 | - if (ContentHelper::contentIs($server, 'text/plain')) { |
|
| 24 | - return $this->getBody($server->getContent()); |
|
| 25 | - } |
|
| 21 | + public function handle($server): array |
|
| 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 |
@@ -11,30 +11,30 @@ |
||
| 11 | 11 | private array $data; |
| 12 | 12 | |
| 13 | 13 | public function __construct() |
| 14 | - { |
|
| 15 | - $this->data = []; |
|
| 16 | - } |
|
| 14 | + { |
|
| 15 | + $this->data = []; |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - public function getBody($content): array |
|
| 18 | + public function getBody($content): array |
|
| 19 | 19 | { |
| 20 | - if (is_array($content)) { |
|
| 21 | - return $content; |
|
| 22 | - } |
|
| 20 | + if (is_array($content)) { |
|
| 21 | + return $content; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - $this->handleSentData($content); |
|
| 24 | + $this->handleSentData($content); |
|
| 25 | 25 | |
| 26 | - return $this->data; |
|
| 26 | + return $this->data; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - private function handleSentData(string $content): void |
|
| 30 | - { |
|
| 31 | - $body = explode('&', $content); |
|
| 29 | + private function handleSentData(string $content): void |
|
| 30 | + { |
|
| 31 | + $body = explode('&', $content); |
|
| 32 | 32 | |
| 33 | - foreach ($body as $parameter) { |
|
| 34 | - $parameterParsed = explode('=', $parameter); |
|
| 33 | + foreach ($body as $parameter) { |
|
| 34 | + $parameterParsed = explode('=', $parameter); |
|
| 35 | 35 | |
| 36 | - $this->data[$parameterParsed[0]] = str_replace("%0A", "\n", $parameterParsed[1]); |
|
| 37 | - } |
|
| 36 | + $this->data[$parameterParsed[0]] = str_replace("%0A", "\n", $parameterParsed[1]); |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | public function next(Handler $handler) |
@@ -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) |
|
| 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) |
|
| 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 |
@@ -12,31 +12,31 @@ |
||
| 12 | 12 | private array $currentData; |
| 13 | 13 | |
| 14 | 14 | public function __construct() |
| 15 | - { |
|
| 16 | - $this->currentData = []; |
|
| 17 | - } |
|
| 15 | + { |
|
| 16 | + $this->currentData = []; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public function getBody($content): array |
|
| 19 | + public function getBody($content): array |
|
| 20 | 20 | { |
| 21 | - $boundary = substr($content, 0, strpos($content, "\r\n")); |
|
| 22 | - $parts = array_slice(explode($boundary, $content), 1); |
|
| 21 | + $boundary = substr($content, 0, strpos($content, "\r\n")); |
|
| 22 | + $parts = array_slice(explode($boundary, $content), 1); |
|
| 23 | 23 | |
| 24 | - foreach ($parts as $part) { |
|
| 25 | - preg_match_all('/"(.+)"+\s+([^\t]+)/', $part, $matches); |
|
| 24 | + foreach ($parts as $part) { |
|
| 25 | + preg_match_all('/"(.+)"+\s+([^\t]+)/', $part, $matches); |
|
| 26 | 26 | |
| 27 | - $this->handleBodySent($matches); |
|
| 28 | - } |
|
| 27 | + $this->handleBodySent($matches); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - return $this->currentData; |
|
| 30 | + return $this->currentData; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - private function handleBodySent(array $matches): void |
|
| 34 | - { |
|
| 35 | - foreach ($matches[1] as $key => $match) { |
|
| 36 | - $matchKey = str_replace(["'", '"'], '', $match); |
|
| 33 | + private function handleBodySent(array $matches): void |
|
| 34 | + { |
|
| 35 | + foreach ($matches[1] as $key => $match) { |
|
| 36 | + $matchKey = str_replace(["'", '"'], '', $match); |
|
| 37 | 37 | |
| 38 | - $this->currentData[$matchKey] = substr($matches[2][$key], 0, -2); |
|
| 39 | - } |
|
| 38 | + $this->currentData[$matchKey] = substr($matches[2][$key], 0, -2); |
|
| 39 | + } |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | public function next(Handler $handler) |