aboutsummaryrefslogtreecommitdiff
path: root/private/View/Output.php
diff options
context:
space:
mode:
authorKevin J Hoerr <kjhoerr@protonmail.com>2017-07-08 13:58:36 -0400
committerKevin J Hoerr <kjhoerr@protonmail.com>2017-07-08 13:58:36 -0400
commit692a4a48d5f8f74a06d0b5890e31887a76a903f3 (patch)
tree9fc39dc20be3b8a442031b85beffc7baa583143b /private/View/Output.php
parent0364d790e9764d91489db21805064ceeb23e3e22 (diff)
downloadaugust-offensive-692a4a48d5f8f74a06d0b5890e31887a76a903f3.tar.gz
august-offensive-692a4a48d5f8f74a06d0b5890e31887a76a903f3.tar.bz2
august-offensive-692a4a48d5f8f74a06d0b5890e31887a76a903f3.zip
Improve exception handling, introduce autoloading
Diffstat (limited to 'private/View/Output.php')
-rw-r--r--private/View/Output.php34
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()
+ ));
+ }
+}