From: Cameron Ball Date: Mon, 8 Sep 2014 09:05:10 +0000 (+0800) Subject: Tentative work on controllers and repositories. X-Git-Url: https://git.cameron1729.xyz/?a=commitdiff_plain;h=f7c0f56d3ba4aa5b5bc6e960518991b80bc4a5c5;p=rock.divinelegy.git Tentative work on controllers and repositories. --- diff --git a/Controllers/AbstractController.php b/Controllers/AbstractController.php new file mode 100644 index 0000000..d6f0637 --- /dev/null +++ b/Controllers/AbstractController.php @@ -0,0 +1,19 @@ +_isJsonResponse = true; + } +} \ No newline at end of file diff --git a/Controllers/HomeController.php b/Controllers/HomeController.php new file mode 100644 index 0000000..fa1c3a5 --- /dev/null +++ b/Controllers/HomeController.php @@ -0,0 +1,13 @@ +'; } + //TODO: Implement public function remove(IDivineEntity $entity) { ; } diff --git a/DataAccess/IRepository.php b/DataAccess/IRepository.php new file mode 100644 index 0000000..1dd8c75 --- /dev/null +++ b/DataAccess/IRepository.php @@ -0,0 +1,13 @@ +dataMapper = $dataMapper; + } + + public function find($id) { + return $this->dataMapper->find($id, 'simfiles'); + } + + public function save(IDivineEntity $entity) { + $this->dataMapper->save($entity); + } + + //TODO: Implement + public function remove(IDivineEntity $entity) { + ; + } +} diff --git a/Services/HttpResponse.php b/Services/HttpResponse.php new file mode 100644 index 0000000..f3c05c9 --- /dev/null +++ b/Services/HttpResponse.php @@ -0,0 +1,89 @@ + $code) || (599 < $code)) { + throw new Exception(sprintf('Invalid HTTP response code, %u', $code)); + } + + $this->_isRedirect = (300 <= $code) && (307 >= $code); + $this->_statusCode = $code; + + return $this; + } + + public function isRedirect() + { + return $this->_isRedirect; + } + + public function setHeader($name, $value) + { + $value = (string) $value; + + $this->_headers[$name] = $value; + + return $this; + } + + public function getHeaders() + { + return $this->_headers; + } + + private function sendHeaders() + { + $statusCodeSent = false; + + if(!count($this->_headers)) { + return $this; + } + + foreach($this->_headers as $headerName => $headerValue) { + if(!$statusCodeSent) { + header( + sprintf('%s:%s', $headerName, $headerValue), + false, + $this->_statusCode); + + $statusCodeSent = true; + } + } + + return $this; + } + + public function setBody($content) + { + $this->_body = $content; + } + + public function getBody() + { + return $this->_body; + } + + + private function sendBody() + { + echo $this->_body; + } + + public function sendResponse() + { + $this->sendHeaders() + ->sendBody(); + } +} diff --git a/Services/IHttpResponse.php b/Services/IHttpResponse.php new file mode 100644 index 0000000..ab3feed --- /dev/null +++ b/Services/IHttpResponse.php @@ -0,0 +1,16 @@ +