lithium\core\ErrorHandler::apply PHP Method

apply() public static method

public static apply ( $object, array $conditions, $handler )
$conditions array
    public static function apply($object, array $conditions, $handler)
    {
        $conditions = $conditions ?: array('type' => 'Exception');
        list($class, $method) = is_string($object) ? explode('::', $object) : $object;
        $wrap = static::$_exceptionHandler;
        $_self = get_called_class();
        $filter = function ($self, $params, $chain) use($_self, $conditions, $handler, $wrap) {
            try {
                return $chain->next($self, $params, $chain);
            } catch (Exception $e) {
                if (!$_self::matches($e, $conditions)) {
                    throw $e;
                }
                return $handler($wrap($e, true), $params);
            }
        };
        if (is_string($class)) {
            Filters::apply($class, $method, $filter);
        } else {
            $class->applyFilter($method, $filter);
        }
    }

Usage Example

Beispiel #1
0
<?php

/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2011, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */
use lithium\core\ErrorHandler;
use lithium\action\Response;
use lithium\net\http\Media;
use lithium\analysis\Debugger;
ErrorHandler::apply('lithium\\action\\Dispatcher::run', array(), function ($info, $params) {
    $stack = Debugger::trace(array('format' => 'array', 'trace' => $info['exception']->getTrace()));
    $exception_class = get_class($info['exception']);
    array_unshift($stack, array('functionRef' => '[exception]', 'file' => $info['exception']->getFile(), 'line' => $info['exception']->getLine()));
    $response = new Response(array('request' => $params['request'], 'status' => $info['exception']->getCode()));
    Media::render($response, compact('info', 'params', 'stack', 'exception_class'), array('controller' => 'errors', 'template' => 'development', 'layout' => 'error', 'request' => $params['request']));
    return $response;
});
All Usage Examples Of lithium\core\ErrorHandler::apply