aboutsummaryrefslogtreecommitdiff
path: root/private/View
diff options
context:
space:
mode:
authorKevin J Hoerr <kjhoerr@submelon.tech>2018-08-26 01:38:28 -0400
committerKevin Hoerr <kjhoerr@submelon.tech>2018-08-31 23:24:45 -0400
commit0965d62be00a7820f97284704dc71f37e661b412 (patch)
tree5a5c9d69062e24aa926eb30447c5ff27e0a65492 /private/View
parent1e3946f04b5b602d3869a285d897acb0ba2b3c35 (diff)
downloadaugust-offensive-0965d62be00a7820f97284704dc71f37e661b412.tar.gz
august-offensive-0965d62be00a7820f97284704dc71f37e661b412.tar.bz2
august-offensive-0965d62be00a7820f97284704dc71f37e661b412.zip
Begin migration to Rust; Add actix-web, diesel as main dependencies
Diffstat (limited to 'private/View')
-rw-r--r--private/View/Main.php104
-rw-r--r--private/View/Output.php28
2 files changed, 0 insertions, 132 deletions
diff --git a/private/View/Main.php b/private/View/Main.php
deleted file mode 100644
index c51e91f..0000000
--- a/private/View/Main.php
+++ /dev/null
@@ -1,104 +0,0 @@
-<?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;
-
- /** @var string TYPE The type of output the client should receive. */
- const TYPE = "json";
-
- /**
- * 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)
- {
- $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 output.
- *
- * @return string
- */
- public function generateResult (): string
- {
- $path = $this->query->getPath();
- if (count($path) >= 1 && $path[0] === "api" && count($path) >= 2) {
- switch (strtolower($path[1])) {
- case "callback":
- $this->result = Controller\Controller::createResult(
- "CALLBACK",
- array(
- "path" => $path,
- "request" => $this->query->getRequest(),
- "content" => $this->query->getContent()
- )
- );
- break;
- default:
- $this->result = Controller\Controller::createResult("NOT_UNDERSTOOD", array($path));
- break;
- }
- } else {
- $this->result = Controller\Controller::createResult("NOT_UNDERSTOOD", array($path));
- }
-
- 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);
- }
-}
diff --git a/private/View/Output.php b/private/View/Output.php
deleted file mode 100644
index af9975e..0000000
--- a/private/View/Output.php
+++ /dev/null
@@ -1,28 +0,0 @@
-<?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.
- *
- * @return string
- */
- public static function json (Model\Result $result): string
- {
- return json_encode(array(
- "Result-Type" => $result->getResultType(),
- "Content" => $result->getResult()
- ));
- }
-}