summaryrefslogtreecommitdiffstats
path: root/config/bootstrap/error.php
blob: dc33bf5884d0bb46bbede79ab3e846054bda68c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
/**
 * First, import the relevant Lithium core classes.
 */
use \lithium\core\ErrorHandler;
use \lithium\analysis\Logger;
use lithium\action\Response;
use lithium\net\http\Media;
 
/**
 * Then, set up a basic logging configuration that will write to a file.
 */
Logger::config(array(
    'error' => array('adapter' => 'File')
));
 
 
ErrorHandler::apply('lithium\action\Dispatcher::run', array(), function($info, $params) {
    $response = new Response(array('request' => $params['request']));
 
    $message = "/(^Template not found|^Controller '\w+' not found|^Action '\w+' not found)/";
    $template = (preg_match($message, $info['message'])) ? '404' : '500';
 
    Logger::write('error', "{$info['file']} : {$info['line']} : {$info['message']}");
    switch($template){
        case '500':
            debug($info);die;
        break;
    }
    Media::render($response, compact('info', 'params'), array(
        'controller' => 'errors',
        'template' => $template,
        'layout' => 'default',
        'request' => $params['request']
    ));
    return $response;
});