diff options
| author | Kevin J Hoerr <kjhoerr@protonmail.com> | 2017-07-08 11:11:53 -0400 |
|---|---|---|
| committer | Kevin J Hoerr <kjhoerr@protonmail.com> | 2017-07-08 11:11:53 -0400 |
| commit | 2d796d48df6f4371111bcbc776ea781e4f45c831 (patch) | |
| tree | 8b70da2114d71d2835b2f58eb2d43083a3ff5a6f /private/View/Main.php | |
| parent | 3b75177580e536ce309d44759eb4d1f772c987ce (diff) | |
| download | august-offensive-2d796d48df6f4371111bcbc776ea781e4f45c831.tar.gz august-offensive-2d796d48df6f4371111bcbc776ea781e4f45c831.tar.bz2 august-offensive-2d796d48df6f4371111bcbc776ea781e4f45c831.zip | |
Expand on query and result, begin sql design
Diffstat (limited to 'private/View/Main.php')
| -rw-r--r-- | private/View/Main.php | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/private/View/Main.php b/private/View/Main.php new file mode 100644 index 0000000..1dcd760 --- /dev/null +++ b/private/View/Main.php @@ -0,0 +1,78 @@ +<?php + +declare(strict_types=1); + +namespace AugustOffensive\View; + +use AugustOffensive\Controller; +use AugustOffensive\Model; + +/** + * Outputs the JSON result by communicating with the controller. + */ +class Main +{ + /** @var Model\Query $query the Query object that generated the request. */ + private $query; + + /** @var Model\Result $result the Result object to be sent to the client. */ + private $result; + + /** + * Prepares the output and environment for the front end of the service. + * + * @param Model\Connection $connection View "Needs to know" model exists. + * + * @return Result + */ + 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'], + $this->generateContent($_SERVER['REQUEST_METHOD']) + ); + + return $this; + } + + /** + * Generates the content of the query based on the request type. + * + * @param string $request The request method on which to base the content. + * + * @return array + */ + public function generateContent (string $request): array + { + $content; + switch ($request) { + case "GET": // GET should always be empty + case "POST": // POST contains moves, account info, etc. + default: + $content = $_REQUEST; + } + return $content; + } + + /** + * Communicates with the controller to generate the JSON result. + * + * @return string + */ + public function generateResult (): string + { + $this->result = Controller\Controller::createResult( + "", + array() + ); + + // generate result + return json_encode(array( + "Result-Type" => $this->result->getResultType(), + "Content" => $this->result->getResult() + )); + } +} |
