@@ 9-27 (lines=19) @@ | ||
6 | use ByJG\Serializer\Formatter\PlainTextFormatter; |
|
7 | use Whoops\Handler\PrettyPageHandler; |
|
8 | ||
9 | class HtmlHandler implements HandleOutputInterface |
|
10 | { |
|
11 | ||
12 | public function writeHeader() |
|
13 | { |
|
14 | header('Content-Type: text/html'); |
|
15 | } |
|
16 | ||
17 | public function writeOutput(ServiceAbstract $instance) |
|
18 | { |
|
19 | $serialized = $instance->getResponse()->getResponseBag()->process(); |
|
20 | return (new PlainTextFormatter())->process($serialized); |
|
21 | } |
|
22 | ||
23 | public function getErrorHandler() |
|
24 | { |
|
25 | return new PrettyPageHandler(); |
|
26 | } |
|
27 | } |
|
28 |
@@ 9-30 (lines=22) @@ | ||
6 | use ByJG\RestServer\Whoops\JsonResponseHandler; |
|
7 | use ByJG\Serializer\Formatter\JsonFormatter; |
|
8 | ||
9 | class JsonHandler implements HandleOutputInterface |
|
10 | { |
|
11 | ||
12 | public function writeHeader() |
|
13 | { |
|
14 | header('Content-Type: application/json'); |
|
15 | // header('Access-Control-Allow-Origin: *'); |
|
16 | // header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method"); |
|
17 | // header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE"); |
|
18 | } |
|
19 | ||
20 | public function writeOutput(ServiceAbstract $instance) |
|
21 | { |
|
22 | $serialized = $instance->getResponse()->getResponseBag()->process(); |
|
23 | return (new JsonFormatter())->process($serialized); |
|
24 | } |
|
25 | ||
26 | public function getErrorHandler() |
|
27 | { |
|
28 | return new JsonResponseHandler(); |
|
29 | } |
|
30 | } |
|
31 |
@@ 9-27 (lines=19) @@ | ||
6 | use ByJG\Serializer\Formatter\XmlFormatter; |
|
7 | use Whoops\Handler\XmlResponseHandler; |
|
8 | ||
9 | class XmlHandler implements HandleOutputInterface |
|
10 | { |
|
11 | public function writeHeader() |
|
12 | { |
|
13 | header('Content-Type: text/xml'); |
|
14 | } |
|
15 | ||
16 | public function writeOutput(ServiceAbstract $instance) |
|
17 | { |
|
18 | ||
19 | $serialized = $instance->getResponse()->getResponseBag()->process(); |
|
20 | return (new XmlFormatter())->process($serialized); |
|
21 | } |
|
22 | ||
23 | public function getErrorHandler() |
|
24 | { |
|
25 | return new XmlResponseHandler(); |
|
26 | } |
|
27 | } |
|
28 |