diff options
Diffstat (limited to 'private/View/Output.php')
| -rw-r--r-- | private/View/Output.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/private/View/Output.php b/private/View/Output.php new file mode 100644 index 0000000..fe42c15 --- /dev/null +++ b/private/View/Output.php @@ -0,0 +1,34 @@ +<?php + +declare(strict_types=1); + +namespace AugustOffensive\View; + +use AugustOffensive\Model; + +/** + * Output formats for Results that are returned to the client. + */ +class Output +{ + /** + * Formats the result into JSON. + * + * @param Model\Result $result The result to return to the client. + * @param bool $prepare Whether to set the content type of the response (default true). + * + * @return string + */ + public static function json (Model\Result $result, bool $prepare = true): string + { + // breaks side effect rule? + if ($prepare) { + header("Content-Type: application/json"); + } + + return json_encode(array( + "Result-Type" => $result->getResultType(), + "Content" => $result->getResult() + )); + } +} |
