Permalink
Browse files

Added controllers for NotFound and Error pages.

  • Loading branch information...
1 parent 1090c1d commit ddb7e606d28c4e112bbcfad4bf1c3b8005685c5e @Evoke-PHP committed Apr 10, 2012
Showing with 158 additions and 0 deletions.
  1. +96 −0 php/src/Evoke/Controller/Error.php
  2. +62 −0 php/src/Evoke/Controller/NotFound.php
@@ -0,0 +1,96 @@
+<?php
+namespace Evoke\Controller;
+
+class Error extends Base
+{
+ /*********************/
+ /* Protected Methods */
+ /*********************/
+
+ /// Initialize the controller by setting the response code to 404 Not Found.
+ protected function initialize()
+ {
+ $this->Response->setResponseCode(500);
+ }
+
+ protected function html5ALL()
+ {
+ $this->xhtmlALL();
+ }
+
+ protected function jsonALL()
+ {
+ $this->Writer->write(array('Code' => '500',
+ 'Message' => $this->getMessage(),
+ 'Title' => 'Internal Server Error'));
+ }
+
+ protected function textALL()
+ {
+ $this->Writer->write(
+ rtrim('500 Internal Server Error ' . $this->getMessage()));
+ }
+
+ protected function xhtmlALL()
+ {
+ $this->startXHTML();
+ $this->writeMessageBoxXML();
+ $this->endXHTML();
+ }
+
+ protected function xmlALL()
+ {
+ $this->writeMessageBoxXML();
+ }
+
+ /*******************/
+ /* Private Methods */
+ /*******************/
+
+ // Get the description of the error.
+ private function getMessage()
+ {
+ $Translator = $this->Factory->getTranslator();
+
+ $description = $Translator->get('Error_Text');
+
+ if (isset($this->params['Exception']) &&
+ $this->params['Exception'] instanceof \Exception)
+ {
+ $description .= "\n" . $this->params['Exception']->getMessage();
+ }
+
+ return $description;
+ }
+
+ /// Write a Message Box in XML showing the Not Found message.
+ private function writeMessageBoxXML()
+ {
+ $Element = $this->Factory->build(
+ 'Evoke\Element\Message\Box',
+ array('Attribs' => array('class' => 'Message_Box System')));
+ $Translator = $this->Factory->getTranslator();
+
+ $description = explode("\n", $this->getMessage());
+ $descriptionWithBreaks = array();
+
+ foreach ($description as $entry)
+ {
+ $descriptionWithBreaks[] = $entry;
+ $descriptionWithBreaks[] = array('br');
+ }
+
+ array_pop($descriptionWithBreaks);
+
+ $this->Writer->write(
+ array('div',
+ array('class' => 'Message_Box System'),
+ array(array('div',
+ array('class' => 'Title'),
+ $Translator->get('Error_Title')),
+ array('div',
+ array('class' => 'Description'),
+ $descriptionWithBreaks))));
+ }
+}
+// EOF
@@ -0,0 +1,62 @@
+<?php
+namespace Evoke\Controller;
+
+class NotFound extends Base
+{
+ /*********************/
+ /* Protected Methods */
+ /*********************/
+
+ /// Initialize the controller by setting the response code to 404 Not Found.
+ protected function initialize()
+ {
+ $this->Response->setResponseCode(404);
+ }
+
+ protected function html5ALL()
+ {
+ $this->xhtmlALL();
+ }
+
+ protected function jsonALL()
+ {
+ $this->Writer->write(array('Code' => '404',
+ 'Text' => 'Not Found'));
+ }
+
+ protected function textALL()
+ {
+ $this->Writer->write('404 Not Found');
+ }
+
+ protected function xhtmlALL()
+ {
+ $this->startXHTML();
+ $this->writeMessageBoxXML();
+ $this->Writer->writeEnd();
+ }
+
+ protected function xmlALL()
+ {
+ $this->writeMessageBoxXML();
+ }
+
+ /*******************/
+ /* Private Methods */
+ /*******************/
+
+ /// Write a Message Box in XML showing the Not Found message.
+ private function writeMessageBoxXML()
+ {
+ $Element = $this->Factory->build(
+ 'Evoke\Element\Message\Box',
+ array('Attribs' => array('class' => 'Message_Box System')));
+ $Translator = $this->Factory->getTranslator();
+
+ $this->Writer->write(
+ $Element->set(
+ array('Description' => $Translator->get('Not_Found_Text'),
+ 'Title' => $Translator->get('Not_Found_Title'))));
+ }
+}
+// EOF

0 comments on commit ddb7e60

Please sign in to comment.