Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added controllers for NotFound and Error pages.

  • Loading branch information...
commit ddb7e606d28c4e112bbcfad4bf1c3b8005685c5e 1 parent 1090c1d
Evoke-PHP authored
96 php/src/Evoke/Controller/Error.php
... ... @@ -0,0 +1,96 @@
  1 +<?php
  2 +namespace Evoke\Controller;
  3 +
  4 +class Error extends Base
  5 +{
  6 + /*********************/
  7 + /* Protected Methods */
  8 + /*********************/
  9 +
  10 + /// Initialize the controller by setting the response code to 404 Not Found.
  11 + protected function initialize()
  12 + {
  13 + $this->Response->setResponseCode(500);
  14 + }
  15 +
  16 + protected function html5ALL()
  17 + {
  18 + $this->xhtmlALL();
  19 + }
  20 +
  21 + protected function jsonALL()
  22 + {
  23 + $this->Writer->write(array('Code' => '500',
  24 + 'Message' => $this->getMessage(),
  25 + 'Title' => 'Internal Server Error'));
  26 + }
  27 +
  28 + protected function textALL()
  29 + {
  30 + $this->Writer->write(
  31 + rtrim('500 Internal Server Error ' . $this->getMessage()));
  32 + }
  33 +
  34 + protected function xhtmlALL()
  35 + {
  36 + $this->startXHTML();
  37 + $this->writeMessageBoxXML();
  38 + $this->endXHTML();
  39 + }
  40 +
  41 + protected function xmlALL()
  42 + {
  43 + $this->writeMessageBoxXML();
  44 + }
  45 +
  46 + /*******************/
  47 + /* Private Methods */
  48 + /*******************/
  49 +
  50 + // Get the description of the error.
  51 + private function getMessage()
  52 + {
  53 + $Translator = $this->Factory->getTranslator();
  54 +
  55 + $description = $Translator->get('Error_Text');
  56 +
  57 + if (isset($this->params['Exception']) &&
  58 + $this->params['Exception'] instanceof \Exception)
  59 + {
  60 + $description .= "\n" . $this->params['Exception']->getMessage();
  61 + }
  62 +
  63 + return $description;
  64 + }
  65 +
  66 + /// Write a Message Box in XML showing the Not Found message.
  67 + private function writeMessageBoxXML()
  68 + {
  69 + $Element = $this->Factory->build(
  70 + 'Evoke\Element\Message\Box',
  71 + array('Attribs' => array('class' => 'Message_Box System')));
  72 + $Translator = $this->Factory->getTranslator();
  73 +
  74 + $description = explode("\n", $this->getMessage());
  75 + $descriptionWithBreaks = array();
  76 +
  77 + foreach ($description as $entry)
  78 + {
  79 + $descriptionWithBreaks[] = $entry;
  80 + $descriptionWithBreaks[] = array('br');
  81 + }
  82 +
  83 + array_pop($descriptionWithBreaks);
  84 +
  85 + $this->Writer->write(
  86 + array('div',
  87 + array('class' => 'Message_Box System'),
  88 + array(array('div',
  89 + array('class' => 'Title'),
  90 + $Translator->get('Error_Title')),
  91 + array('div',
  92 + array('class' => 'Description'),
  93 + $descriptionWithBreaks))));
  94 + }
  95 +}
  96 +// EOF
62 php/src/Evoke/Controller/NotFound.php
... ... @@ -0,0 +1,62 @@
  1 +<?php
  2 +namespace Evoke\Controller;
  3 +
  4 +class NotFound extends Base
  5 +{
  6 + /*********************/
  7 + /* Protected Methods */
  8 + /*********************/
  9 +
  10 + /// Initialize the controller by setting the response code to 404 Not Found.
  11 + protected function initialize()
  12 + {
  13 + $this->Response->setResponseCode(404);
  14 + }
  15 +
  16 + protected function html5ALL()
  17 + {
  18 + $this->xhtmlALL();
  19 + }
  20 +
  21 + protected function jsonALL()
  22 + {
  23 + $this->Writer->write(array('Code' => '404',
  24 + 'Text' => 'Not Found'));
  25 + }
  26 +
  27 + protected function textALL()
  28 + {
  29 + $this->Writer->write('404 Not Found');
  30 + }
  31 +
  32 + protected function xhtmlALL()
  33 + {
  34 + $this->startXHTML();
  35 + $this->writeMessageBoxXML();
  36 + $this->Writer->writeEnd();
  37 + }
  38 +
  39 + protected function xmlALL()
  40 + {
  41 + $this->writeMessageBoxXML();
  42 + }
  43 +
  44 + /*******************/
  45 + /* Private Methods */
  46 + /*******************/
  47 +
  48 + /// Write a Message Box in XML showing the Not Found message.
  49 + private function writeMessageBoxXML()
  50 + {
  51 + $Element = $this->Factory->build(
  52 + 'Evoke\Element\Message\Box',
  53 + array('Attribs' => array('class' => 'Message_Box System')));
  54 + $Translator = $this->Factory->getTranslator();
  55 +
  56 + $this->Writer->write(
  57 + $Element->set(
  58 + array('Description' => $Translator->get('Not_Found_Text'),
  59 + 'Title' => $Translator->get('Not_Found_Title'))));
  60 + }
  61 +}
  62 +// EOF

0 comments on commit ddb7e60

Please sign in to comment.
Something went wrong with that request. Please try again.