Framework Skeleton: Setting STDERR Controllers

Error controllers are STDERR MVC API components created to implement exception-specific customization of reporting and rendering.

How are they located?

Controllers are detected based on exception thrown by finding a <exception> tag whose value of "class" attribute matches. Once a match is found, controller class name will be identified as value of "controller" attribute, otherwise value of "controller" defined in parent <exceptions> tag is used. If any is found, its file will be loaded from disk in folder defined by application>paths>controllers tag as a PHP file with identical name as class (without namespace).

If no controller is found, execution continues as they are not mandatory!

How to write a controller?

As MVC controllers, they have access to exception they route, models they need to interact with and pending response. In order to be recognized by API as controllers, they must extend Lucinda\MVC\STDERR\Controller and implement its required run method. By extending, they gain access to Lucinda\MVC\STDERR\Application, Lucinda\MVC\STDERR\Request and Lucinda\MVC\STDERR\Response objects already compiled by API.

Example:

class MyController extends \Lucinda\MVC\STDERR\Controller { public function run() { if ($this->request->getException() instanceof TestException) { $this->response->setView($this->application->getViewsPath()."/test"); } else { $this->response->setView($this->application->getViewsPath()."/normal"); } } }

What does framework already come with?

Framework routes most Exceptions it knows of in stderr.xml, leaving out those that need no derivation from global policy. All controllers are located in folder set by application>paths>controllers stderr.xml tag based on value of "class" attribute of <exceptions>/<exception> tag. Framework comes with two error controllers preinstalled but users can add their own:

Notes:
1. Having a controller is mandatory whenever developers do not response to be than just a static view file and a http status code.
2. Both controllers provided by framework are open for change. They have a consistent chance of being altered by developers for peculiar application needs!

ErrorsController

This controller is to be used whenever exception routed is an error of some sort. Because almost all exceptions routed are errors, framework sets it up globally in <exceptions> tag as well as locally in <exception> children as "controller" attribute. Its job is to setup response:

SecurityPacketController

This controller routes Lucinda\Framework\SecurityPacket, which encapsulates results of authentication & authorization through a packet with following coordinates:

Controller's job is to decide where to send received packet:


Share