This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
Sequenzia/lib/Rails/ActionController/ExceptionHandler.php
2013-10-26 10:53:37 -05:00

53 lines
1.1 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 by
* overriding handle(). Although this isn't needed for basic handling,
* default setup should work fine.
* 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;
}
}