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);
}
}