From: Cameron Ball Date: Mon, 8 Sep 2014 14:01:34 +0000 (+0800) Subject: Implement a basic controller. DI looks to be working. X-Git-Url: https://git.cameron1729.xyz/?a=commitdiff_plain;h=7ba2da0a7fc72061a58bf320f8baadab15d37f3d;p=rock.divinelegy.git Implement a basic controller. DI looks to be working. --- diff --git a/Controllers/AbstractController.php b/Controllers/AbstractController.php deleted file mode 100644 index d6f0637..0000000 --- a/Controllers/AbstractController.php +++ /dev/null @@ -1,19 +0,0 @@ -_isJsonResponse = true; - } -} \ No newline at end of file diff --git a/Controllers/HomeController.php b/Controllers/HomeController.php deleted file mode 100644 index fa1c3a5..0000000 --- a/Controllers/HomeController.php +++ /dev/null @@ -1,13 +0,0 @@ -_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(); + } +} diff --git a/DataAccess/DataMapper/DataMapper.php b/DataAccess/DataMapper/DataMapper.php index be1bf0a..8ee898d 100644 --- a/DataAccess/DataMapper/DataMapper.php +++ b/DataAccess/DataMapper/DataMapper.php @@ -22,7 +22,7 @@ class DataMapper implements IDataMapper $options = array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION); - $this->_db = new PDO($dsn, $username, null, $options); + $this->_db = new PDO($dsn, $username, $password, $options); $this->_maps = include $maps; } diff --git a/DataAccess/IRepository.php b/DataAccess/IRepository.php deleted file mode 100644 index 1dd8c75..0000000 --- a/DataAccess/IRepository.php +++ /dev/null @@ -1,13 +0,0 @@ -dataMapper->find($id, 'simfiles'); + return $this->dataMapper->find($id, 'Simfile'); } - public function save(IDivineEntity $entity) { + public function save(ISimfile $entity) { $this->dataMapper->save($entity); } //TODO: Implement - public function remove(IDivineEntity $entity) { + public function remove(ISimfile $entity) { ; } } diff --git a/Domain/Entities/AbstractEntity.php b/Domain/Entities/AbstractEntity.php index dfe0268..7d36796 100644 --- a/Domain/Entities/AbstractEntity.php +++ b/Domain/Entities/AbstractEntity.php @@ -10,7 +10,7 @@ abstract class AbstractEntity implements IDivineEntity public function setId($id) { if(isset($this->id)) { - // throw new Exception('ID already set.'); + throw new Exception('ID already set.'); } $this->id = $id; diff --git a/Domain/Entities/StepMania/ISimfile.php b/Domain/Entities/StepMania/ISimfile.php index e25aac8..b135f89 100644 --- a/Domain/Entities/StepMania/ISimfile.php +++ b/Domain/Entities/StepMania/ISimfile.php @@ -3,8 +3,9 @@ namespace Domain\Entities\StepMania; use Domain\VOs\StepMania\IStepChart; +use Domain\Entities\IDivineEntity; -interface ISimfile +interface ISimfile extends IDivineEntity { public function getTitle(); public function getArtist(); diff --git a/Services/HttpResponse.php b/Services/HttpResponse.php index f3c05c9..26c6e43 100644 --- a/Services/HttpResponse.php +++ b/Services/HttpResponse.php @@ -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() diff --git a/Services/IHttpResponse.php b/Services/IHttpResponse.php index ab3feed..d2c8f7f 100644 --- a/Services/IHttpResponse.php +++ b/Services/IHttpResponse.php @@ -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(); diff --git a/composer.json b/composer.json index 2ecc563..8f82601 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,9 @@ "autoload": { "psr-0": { "Domain" : "./", - "DataAccess" : "./" + "DataAccess" : "./", + "Controllers" : "./", + "Services" : "./" }, "files" : ["./DataAccess/functions.php"] } diff --git a/config/DI.php b/config/DI.php index 915ff7c..8c4c90f 100644 --- a/config/DI.php +++ b/config/DI.php @@ -1,5 +1,12 @@ DI\object('Domain\Entities\Bar'), + //values + 'datamapper.maps' => '../config/DataMaps.php', + + 'Domain\Entities\StepMania\ISimfile' => DI\object('Domain\Entities\StepMania\Simfile'), + 'Services\IHttpResponse' => DI\object('Services\HttpResponse'), + 'DataAccess\StepMania\ISimfileRepository' => DI\object('DataAccess\StepMania\SimfileRepository'), + 'DataAccess\DataMapper\IDataMapper' => DI\object('DataAccess\DataMapper\DataMapper') + ->constructor(DI\link('datamapper.maps')), ]; diff --git a/public_html/index.php b/public_html/index.php index b40bf61..6a786c1 100644 --- a/public_html/index.php +++ b/public_html/index.php @@ -14,52 +14,57 @@ use Domain\ConstantsAndTypes\SimfileConstants; $containerBuilder = new DI\ContainerBuilder(); $containerBuilder->addDefinitions('../config/DI.php'); +$containerBuilder->useAutowiring(true); $container = $containerBuilder->build(); + +$indexController = $container->get('Controllers\IndexController'); +$indexController->getAction(); + /* @var $foo Domain\Entities\Foo */ //$foo = $container->get('Domain\Entities\Foo'); //$foo->returnMe(); - -$DataMapper = new \DataAccess\DataMapper\DataMapper('../config/DataMaps.php'); -$user = $DataMapper->find(1,'User'); - -$simfileFactory = new SimfileFactory(); -$simfileBuilder = new SimfileBuilder($simfileFactory); -$simfileStepByStepBuilder = new SimfileStepByStepBuilder($simfileBuilder); - -$danceMode = new DanceMode('dance-single'); -$difficulty = new Difficulty('challenge'); -$stepArtist = new StepArtist('Someone new fuck'); -$artist = new Artist('A brand new awesome artist!'); -$rating = '10'; - -$bpm = new BPM('256', '128'); -$stepChart = new StepChart($danceMode, - $difficulty, - $stepArtist, - $rating); - -$steps = array($stepChart); - - -$simfile = $simfileStepByStepBuilder->With_Title('Brand New Simfile') - ->With_Artist($artist) - ->With_Uploader($user) - ->With_BPM($bpm) - ->With_BpmChanges(SimfileConstants::NO_BPM_CHANGES) - ->With_Stops(SimfileConstants::NO_STOPS) - ->With_FgChanges(SimfileConstants::NO_FG_CHANGES) - ->With_BgChanges(SimfileConstants::NO_BG_CHANGES) - ->With_Steps($steps) - ->build(); - - -//$user->setId(NULL); - -$simfile = $DataMapper->find(1, 'Simfile'); -$simfile->addStepChart($stepChart); -$DataMapper->save($simfile); +// +//$DataMapper = new \DataAccess\DataMapper\DataMapper('../config/DataMaps.php'); +//$user = $DataMapper->find(1,'User'); +// +//$simfileFactory = new SimfileFactory(); +//$simfileBuilder = new SimfileBuilder($simfileFactory); +//$simfileStepByStepBuilder = new SimfileStepByStepBuilder($simfileBuilder); +// +//$danceMode = new DanceMode('dance-single'); +//$difficulty = new Difficulty('challenge'); +//$stepArtist = new StepArtist('Someone new fuck'); +//$artist = new Artist('A brand new awesome artist!'); +//$rating = '10'; +// +//$bpm = new BPM('256', '128'); +//$stepChart = new StepChart($danceMode, +// $difficulty, +// $stepArtist, +// $rating); +// +//$steps = array($stepChart); +// +// +//$simfile = $simfileStepByStepBuilder->With_Title('Brand New Simfile') +// ->With_Artist($artist) +// ->With_Uploader($user) +// ->With_BPM($bpm) +// ->With_BpmChanges(SimfileConstants::NO_BPM_CHANGES) +// ->With_Stops(SimfileConstants::NO_STOPS) +// ->With_FgChanges(SimfileConstants::NO_FG_CHANGES) +// ->With_BgChanges(SimfileConstants::NO_BG_CHANGES) +// ->With_Steps($steps) +// ->build(); +// +// +////$user->setId(NULL); +// +//$simfile = $DataMapper->find(1, 'Simfile'); +//$simfile->addStepChart($stepChart); +//$DataMapper->save($simfile);