Implement a basic controller. DI looks to be working.
authorCameron Ball <c.ball1729@gmail.com>
Mon, 8 Sep 2014 14:01:34 +0000 (22:01 +0800)
committerCameron Ball <c.ball1729@gmail.com>
Mon, 8 Sep 2014 14:01:34 +0000 (22:01 +0800)
14 files changed:
Controllers/AbstractController.php [deleted file]
Controllers/HomeController.php [deleted file]
Controllers/IndexController.php [new file with mode: 0644]
DataAccess/DataMapper/DataMapper.php
DataAccess/IRepository.php [deleted file]
DataAccess/StepMania/ISimfileRepository.php
DataAccess/StepMania/SimfileRepository.php
Domain/Entities/AbstractEntity.php
Domain/Entities/StepMania/ISimfile.php
Services/HttpResponse.php
Services/IHttpResponse.php
composer.json
config/DI.php
public_html/index.php

diff --git a/Controllers/AbstractController.php b/Controllers/AbstractController.php
deleted file mode 100644 (file)
index d6f0637..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-<?php
-
-namespace Controllers;
-
-use Controllers\IDivineController;
-
-abstract class AbstractController implements IDivineController
-{
-    protected $_isJsonResponse;
-    protected $_response;
-    
-    
-    public function __construct
-    
-    public function setJsonResponse()
-    {
-        $this->_isJsonResponse = true;
-    }
-}
\ No newline at end of file
diff --git a/Controllers/HomeController.php b/Controllers/HomeController.php
deleted file mode 100644 (file)
index fa1c3a5..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-class HomeController
-{
-    
-    private $content;
-    
-    
-    public function defaultAction()
-    {
-        
-    }
-}
diff --git a/Controllers/IndexController.php b/Controllers/IndexController.php
new file mode 100644 (file)
index 0000000..a7f0c98
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+namespace Controllers;
+
+use DataAccess\StepMania\ISimfileRepository;
+use Services\IHttpResponse;
+
+class IndexController implements IDivineController
+{
+    
+    private $_content;
+    private $_simfileRepository;
+    private $_jsonResponse;
+    private $_response;
+    
+    //override
+    public function __construct(
+        IHttpResponse $response,
+        ISimfileRepository $repository
+    ) {
+        $this->_response = $response;
+        $this->_simfileRepository = $repository;
+    }
+    
+    public function setJsonResponse() {
+        $this->_jsonResponse = true;
+    }
+        
+    public function getAction() {
+        /* @var $simfile Domain\Entities\StepMania\ISimfile */
+        $simfile = $this->_simfileRepository->find(1);
+        $modes = array();
+        /* @var $steps Domain\VOs\StepMania\IStepChart */
+        foreach ($simfile->getSteps() as $steps) {
+            $modes[] = $steps->getArtist()->getTag();
+        }
+        
+        $this->_response->setHeader('Content-Type', 'application/json')
+                        ->setBody(json_encode($modes))
+                        ->sendResponse();
+    }
+}
index be1bf0a..8ee898d 100644 (file)
@@ -22,7 +22,7 @@ class DataMapper implements IDataMapper
         $options = array(PDO::ATTR_EMULATE_PREPARES => false,\r
                          PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);\r
         \r
-        $this->_db = new PDO($dsn, $username, null, $options);        \r
+        $this->_db = new PDO($dsn, $username, $password, $options);        \r
         $this->_maps = include $maps;\r
     }\r
     \r
diff --git a/DataAccess/IRepository.php b/DataAccess/IRepository.php
deleted file mode 100644 (file)
index 1dd8c75..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-namespace DataAccess;
-
-use Domain\Entities\IDivineEntity;
-
-interface IRepository
-{
-    public function find($id);
-    public function save(IDivineEntity $entity);
-    public function remove(IDivineEntity $entity);
-}
-    
index 30187d6..30a8264 100644 (file)
@@ -1,12 +1,13 @@
-<?php\r
-\r
-namespace DataAccess\StepMania;\r
-\r
-use Domain\Entities\StepMania\Simfile;\r
-\r
-interface ISimfileRepository\r
-{\r
-    public function find($id);\r
-    public function save(Simfile $simfile);\r
-    public function remove(Simfile $simfile);\r
-}\r
+<?php
+
+namespace DataAccess\StepMania;
+
+use Domain\Entities\StepMania\ISimfile;
+
+interface ISimfileRepository
+{
+    public function find($id);
+    public function save(ISimfile $entity);
+    public function remove(ISimfile $entity);
+}
+    
index dcc97a7..451a912 100644 (file)
@@ -2,12 +2,12 @@
 \r
 namespace DataAccess\StepMania;\r
 \r
-use DataAccess\IRepository;\r
+use DataAccess\StepMania\ISimfileRepository;\r
 use DataAccess\DataMapper\IDataMapper;\r
-use Domain\Entities\IDivineEntity;\r
+use Domain\Entities\StepMania\ISimfile;\r
 \r
 //TODO: Implement some sort of caching. Probably OK for now not to worry.\r
-class SimfileRepository implements IRepository\r
+class SimfileRepository implements ISimfileRepository\r
 {\r
     private $dataMapper;\r
     \r
@@ -16,15 +16,15 @@ class SimfileRepository implements IRepository
     }\r
     \r
     public function find($id) {\r
-        return $this->dataMapper->find($id, 'simfiles');\r
+        return $this->dataMapper->find($id, 'Simfile');\r
     }\r
     \r
-    public function save(IDivineEntity $entity) {\r
+    public function save(ISimfile $entity) {\r
         $this->dataMapper->save($entity);\r
     }\r
     \r
     //TODO: Implement\r
-    public function remove(IDivineEntity $entity) {\r
+    public function remove(ISimfile $entity) {\r
         ;\r
     }\r
 }\r
index dfe0268..7d36796 100644 (file)
@@ -10,7 +10,7 @@ abstract class AbstractEntity implements IDivineEntity
     \r
     public function setId($id) {\r
         if(isset($this->id)) {\r
-        //    throw new Exception('ID already set.');\r
+            throw new Exception('ID already set.');\r
         }\r
         \r
         $this->id = $id;\r
index e25aac8..b135f89 100644 (file)
@@ -3,8 +3,9 @@
 namespace Domain\Entities\StepMania;\r
 \r
 use Domain\VOs\StepMania\IStepChart;\r
+use Domain\Entities\IDivineEntity;\r
 \r
-interface ISimfile\r
+interface ISimfile extends IDivineEntity\r
 {\r
     public function getTitle();\r
     public function getArtist();\r
index f3c05c9..26c6e43 100644 (file)
@@ -68,6 +68,8 @@ class HttpResponse implements IHttpResponse
     public function setBody($content)
     {
         $this->_body = $content;
+        
+        return $this;
     }
     
     public function getBody()
@@ -79,6 +81,8 @@ class HttpResponse implements IHttpResponse
     private function sendBody()
     {
         echo $this->_body;
+        
+        return $this;
     }
         
     public function sendResponse()
index ab3feed..d2c8f7f 100644 (file)
@@ -9,7 +9,7 @@ interface IHttpResponse
     public function setStatusCode($code);
     public function setHeader($name, $value);
     public function getHeaders();
-    public function setBody();
+    public function setBody($body);
     public function getBody();
     public function isRedirect();
     public function sendResponse();
index 2ecc563..8f82601 100644 (file)
@@ -5,7 +5,9 @@
     "autoload": {\r
         "psr-0": {\r
             "Domain" : "./",\r
-            "DataAccess" : "./"\r
+            "DataAccess" : "./",\r
+            "Controllers" : "./",\r
+            "Services" : "./"\r
         },\r
         "files" : ["./DataAccess/functions.php"]\r
     }\r
index 915ff7c..8c4c90f 100644 (file)
@@ -1,5 +1,12 @@
 <?php\r
 \r
 return [\r
-    'Domain\Entities\BarInterface' => DI\object('Domain\Entities\Bar'),\r
+    //values\r
+    'datamapper.maps' => '../config/DataMaps.php',\r
+    \r
+    'Domain\Entities\StepMania\ISimfile' => DI\object('Domain\Entities\StepMania\Simfile'),\r
+    'Services\IHttpResponse' => DI\object('Services\HttpResponse'),\r
+    'DataAccess\StepMania\ISimfileRepository' => DI\object('DataAccess\StepMania\SimfileRepository'),\r
+    'DataAccess\DataMapper\IDataMapper' => DI\object('DataAccess\DataMapper\DataMapper')\r
+        ->constructor(DI\link('datamapper.maps')),   \r
 ];\r
index b40bf61..6a786c1 100644 (file)
@@ -14,52 +14,57 @@ use Domain\ConstantsAndTypes\SimfileConstants;
 \r
 $containerBuilder = new DI\ContainerBuilder();\r
 $containerBuilder->addDefinitions('../config/DI.php');\r
+$containerBuilder->useAutowiring(true);\r
 \r
 $container = $containerBuilder->build();\r
 \r
+\r
+$indexController = $container->get('Controllers\IndexController');\r
+$indexController->getAction();\r
+\r
 /* @var $foo Domain\Entities\Foo */\r
 //$foo = $container->get('Domain\Entities\Foo');\r
 //$foo->returnMe();\r
-\r
-$DataMapper = new \DataAccess\DataMapper\DataMapper('../config/DataMaps.php');\r
-$user = $DataMapper->find(1,'User');\r
-\r
-$simfileFactory = new SimfileFactory();\r
-$simfileBuilder = new SimfileBuilder($simfileFactory);\r
-$simfileStepByStepBuilder = new SimfileStepByStepBuilder($simfileBuilder);\r
-\r
-$danceMode = new DanceMode('dance-single');\r
-$difficulty = new Difficulty('challenge');\r
-$stepArtist = new StepArtist('Someone new fuck');\r
-$artist = new Artist('A brand new awesome artist!');\r
-$rating = '10';\r
-\r
-$bpm = new BPM('256', '128');\r
-$stepChart = new StepChart($danceMode,\r
-    $difficulty,\r
-    $stepArtist,\r
-    $rating);\r
-\r
-$steps = array($stepChart);\r
-\r
-\r
-$simfile = $simfileStepByStepBuilder->With_Title('Brand New Simfile')\r
-                                    ->With_Artist($artist)\r
-                                    ->With_Uploader($user)\r
-                                    ->With_BPM($bpm)\r
-                                    ->With_BpmChanges(SimfileConstants::NO_BPM_CHANGES)\r
-                                    ->With_Stops(SimfileConstants::NO_STOPS)\r
-                                    ->With_FgChanges(SimfileConstants::NO_FG_CHANGES)\r
-                                    ->With_BgChanges(SimfileConstants::NO_BG_CHANGES)\r
-                                    ->With_Steps($steps)\r
-                                    ->build();\r
-\r
-\r
-//$user->setId(NULL);\r
-\r
-$simfile = $DataMapper->find(1, 'Simfile');\r
-$simfile->addStepChart($stepChart);\r
-$DataMapper->save($simfile);\r
+//\r
+//$DataMapper = new \DataAccess\DataMapper\DataMapper('../config/DataMaps.php');\r
+//$user = $DataMapper->find(1,'User');\r
+//\r
+//$simfileFactory = new SimfileFactory();\r
+//$simfileBuilder = new SimfileBuilder($simfileFactory);\r
+//$simfileStepByStepBuilder = new SimfileStepByStepBuilder($simfileBuilder);\r
+//\r
+//$danceMode = new DanceMode('dance-single');\r
+//$difficulty = new Difficulty('challenge');\r
+//$stepArtist = new StepArtist('Someone new fuck');\r
+//$artist = new Artist('A brand new awesome artist!');\r
+//$rating = '10';\r
+//\r
+//$bpm = new BPM('256', '128');\r
+//$stepChart = new StepChart($danceMode,\r
+//    $difficulty,\r
+//    $stepArtist,\r
+//    $rating);\r
+//\r
+//$steps = array($stepChart);\r
+//\r
+//\r
+//$simfile = $simfileStepByStepBuilder->With_Title('Brand New Simfile')\r
+//                                    ->With_Artist($artist)\r
+//                                    ->With_Uploader($user)\r
+//                                    ->With_BPM($bpm)\r
+//                                    ->With_BpmChanges(SimfileConstants::NO_BPM_CHANGES)\r
+//                                    ->With_Stops(SimfileConstants::NO_STOPS)\r
+//                                    ->With_FgChanges(SimfileConstants::NO_FG_CHANGES)\r
+//                                    ->With_BgChanges(SimfileConstants::NO_BG_CHANGES)\r
+//                                    ->With_Steps($steps)\r
+//                                    ->build();\r
+//\r
+//\r
+////$user->setId(NULL);\r
+//\r
+//$simfile = $DataMapper->find(1, 'Simfile');\r
+//$simfile->addStepChart($stepChart);\r
+//$DataMapper->save($simfile);\r
 \r
 \r
 \r