aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin J Hoerr <kjhoerr@protonmail.com>2017-06-21 23:03:15 -0400
committerKevin J Hoerr <kjhoerr@protonmail.com>2017-06-21 23:03:15 -0400
commit92465af465886f14f22bb60dd974a93baa9c5322 (patch)
tree2f9a660371cab99e842e4a93ad9818128e6e3390
parent4406034152597a049de0706520a274f6e6271fe9 (diff)
downloadaugust-offensive-92465af465886f14f22bb60dd974a93baa9c5322.tar.gz
august-offensive-92465af465886f14f22bb60dd974a93baa9c5322.tar.bz2
august-offensive-92465af465886f14f22bb60dd974a93baa9c5322.zip
Add basic MVC structure with namespacing and PHPDOC (not tested)
-rw-r--r--README.md2
-rw-r--r--index.php41
-rw-r--r--private/controller/Controller.php16
-rw-r--r--private/model/Connection.php19
-rw-r--r--private/view/Result.php39
5 files changed, 116 insertions, 1 deletions
diff --git a/README.md b/README.md
index 968ce67..5224954 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,6 @@ The main goal of August Offensive is to enable players to interact with the serv
## Technical Objectives
-The web service will provide a RESTful API that is written in PHP 7 and connects to a PostGreSQL database. This connection will be managed behind an abstraction layer using PDO. The service will handle users and their game sessions.
+The web service will provide a RESTful API that is written in PHP 7 and connects to a PostGreSQL database. This connection will be managed behind an abstraction layer using PDO. The service will handle users and their game sessions. In addition, all PHP code shall follow PSR-1, PSR-2, PSR-4, and PSR-5 coding standards. It is also recommended to try to write as immutably as possible.
The front-end of this project will be written using [Elm](http://elm-lang.org/). Work on the front-end portion will not begin until August Offensive's web API has reached relative stability. The version for target stability is alpha 1.0.0.
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..3e770fe
--- /dev/null
+++ b/index.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace AugustOffensive;
+
+include 'private/view/Result.php';
+include 'private/model/Connection.php';
+
+use AugustOffensive\view;
+use AugustOffensive\model;
+
+/**
+ * Constructive controller and initializer API for the service.
+ */
+class Api
+{
+ /** @var \Connection $connection the model database interface */
+ private $connection;
+
+ /** @var \Result $view the view interface that outputs result of the query */
+ private $view;
+
+ /**
+ * Initiates database connection and forwards environment to the view.
+ *
+ * @return Api
+ */
+ public function __construct ()
+ {
+ $connection = new model\Connection();
+ $view = new view\Result($connection);
+
+ // Provide hook for connecting through controller to justify query
+ $result = $view->collect();
+
+ // Leak the data
+ echo $result;
+ }
+}
+
+new Api();
+
diff --git a/private/controller/Controller.php b/private/controller/Controller.php
new file mode 100644
index 0000000..73d0210
--- /dev/null
+++ b/private/controller/Controller.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace AugustOffensive\controller;
+
+include '../model/Connection.php';
+
+use AugustOffensive\model;
+
+/**
+ * Static controller class for interfacing between the view and the model.
+ */
+class Controller
+{
+ //
+}
+
diff --git a/private/model/Connection.php b/private/model/Connection.php
new file mode 100644
index 0000000..26632f7
--- /dev/null
+++ b/private/model/Connection.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace AugustOffensive\model;
+
+/**
+ * Model connection class for connecting to database via PDO.
+ */
+class Connection
+{
+ /**
+ * Initiates connection to PostGreSQL database.
+ *
+ * @return Connection
+ */
+ public function __construct ()
+ {
+ //
+ }
+}
diff --git a/private/view/Result.php b/private/view/Result.php
new file mode 100644
index 0000000..5241e0c
--- /dev/null
+++ b/private/view/Result.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace AugustOffensive\view;
+
+include '../controller/Controller.php';
+include '../model/Connection.php';
+
+use AugustOffensive\controller;
+use AugustOffensive\model;
+
+/**
+ * Outputs the JSON result by communicating with the controller.
+ */
+class Result
+{
+ /**
+ * Prepares the output and environment for the front end of the service.
+ *
+ * @param \Connection $connection "needs to know" model exists
+ *
+ * @return Result
+ */
+ public function __construct (Connection $connection)
+ {
+ header("Content-Type: application/json");
+ //
+ }
+
+ /**
+ * Communicates with the controller to generate the JSON result.
+ *
+ * @return array $result resulting sendback object generated from query.
+ */
+ public function collect ()
+ {
+ //
+ return array();
+ }
+}