Create a plugin that adds a filter on the 'dispatch_exception' filter. The argument passed in is the exception. Return whatever other content you want. As long as whatever you return is not the exception, it will be displayed.
<?php
namespace Plugin\ExceptionHandler;
use Alloy;
/**
* ExceptionHandler Plugin
*/
class Plugin
{
/**
* Initialize plguin
*/
public function __construct(Alloy\Kernel $kernel)
{
// Add 'errorDisplay' method as callback for 'dispatch_exception' filter
$kernel->events()->addFilter('dispatch_exception', 'error_display', array($this, 'errorDisplay'));
}
/**
* Wrap new layout view around result content
*/
public function errorDisplay($content)
{
$kernel = \Kernel();
$request = $kernel->request();
// Render direct layout
$content = new \Alloy\View\Template('error');
$content->path($kernel->config('path.layouts'))
->format($request->format)
->set(array('content' => "Oh noes! Something terrible happened!"));
// Could also perform a custom dispatch...
// $content = $kernel->dispatch('Error', 'showError');
return $content;
}
}