diff options
| author | Kevin J Hoerr <kjhoerr@protonmail.com> | 2017-07-08 13:58:36 -0400 |
|---|---|---|
| committer | Kevin J Hoerr <kjhoerr@protonmail.com> | 2017-07-08 13:58:36 -0400 |
| commit | 692a4a48d5f8f74a06d0b5890e31887a76a903f3 (patch) | |
| tree | 9fc39dc20be3b8a442031b85beffc7baa583143b /private/View/Main.php | |
| parent | 0364d790e9764d91489db21805064ceeb23e3e22 (diff) | |
| download | august-offensive-692a4a48d5f8f74a06d0b5890e31887a76a903f3.tar.gz august-offensive-692a4a48d5f8f74a06d0b5890e31887a76a903f3.tar.bz2 august-offensive-692a4a48d5f8f74a06d0b5890e31887a76a903f3.zip | |
Improve exception handling, introduce autoloading
Diffstat (limited to 'private/View/Main.php')
| -rw-r--r-- | private/View/Main.php | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/private/View/Main.php b/private/View/Main.php index 1dcd760..746c2bb 100644 --- a/private/View/Main.php +++ b/private/View/Main.php @@ -18,6 +18,9 @@ class Main /** @var Model\Result $result the Result object to be sent to the client. */ private $result; + /** @var string TYPE The type of output the client should receive. */ + private const TYPE = "json"; + /** * Prepares the output and environment for the front end of the service. * @@ -27,8 +30,6 @@ class Main */ public function __construct (Model\Connection $connection) { - header("Content-Type: application/json"); - $this->query = Controller\Controller::createQuery( explode('/', trim($_SERVER['PATH_INFO'] ?? '/api', '/')), $_SERVER['REQUEST_METHOD'], @@ -58,7 +59,7 @@ class Main } /** - * Communicates with the controller to generate the JSON result. + * Communicates with the controller to generate the output. * * @return string */ @@ -69,10 +70,19 @@ class Main array() ); - // generate result - return json_encode(array( - "Result-Type" => $this->result->getResultType(), - "Content" => $this->result->getResult() - )); + return self::generateOutput($this->result); + } + + /** + * Creates output of the result based on the defined constant TYPE. + * + * @param Model\Result $result The result to be sent to the client. + * + * @return string + */ + public static function generateOutput (Model\Result $result): string + { + $type = self::TYPE; + return Output::$type($result); } } |
