Sequenzia/lib/Rails/ActionController/ExceptionHandler.php
2013-10-02 11:14:53 -05:00

51 lines
1.0 KiB
PHP
Executable File

<?php
namespace Rails\ActionController;
use Rails;
use Rails\ActionController\Base;
/**
* Basic use:
* Create a class that extends this one.
* According to Exception or status, change the value of $template
* The system will render that template.
*/
abstract class ExceptionHandler extends Base
{
protected $exception;
protected $template = 'exception';
public function handle()
{
switch ($this->status()) {
case 404:
$this->template = '404';
break;
default:
$this->template = '500';
break;
}
}
public function handleException(\Exception $e)
{
$this->exception = $e;
$this->setLayout(false);
$this->runAction("handle");
if (!$this->responded()) {
$this->render(['action' => $this->template]);
}
$this->_create_response_body();
}
public function actionRan()
{
return true;
}
}