Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
/**
3
 * Whoops - php errors for cool kids
4
 * @author Filipe Dobreira <http://github.com/filp>
5
 */
6
 
7
namespace Whoops\Handler;
8
 
9
use InvalidArgumentException;
10
 
11
/**
12
 * Wrapper for Closures passed as handlers. Can be used
13
 * directly, or will be instantiated automagically by Whoops\Run
14
 * if passed to Run::pushHandler
15
 */
16
class CallbackHandler extends Handler
17
{
18
    /**
19
     * @var callable
20
     */
21
    protected $callable;
22
 
23
    /**
24
     * @throws InvalidArgumentException If argument is not callable
25
     * @param  callable                 $callable
26
     */
27
    public function __construct($callable)
28
    {
29
        if (!is_callable($callable)) {
30
            throw new InvalidArgumentException(
31
                'Argument to ' . __METHOD__ . ' must be valid callable'
32
            );
33
        }
34
 
35
        $this->callable = $callable;
36
    }
37
 
38
    /**
39
     * @return int|null
40
     */
41
    public function handle()
42
    {
43
        $exception = $this->getException();
44
        $inspector = $this->getInspector();
45
        $run       = $this->getRun();
46
        $callable  = $this->callable;
47
 
48
        // invoke the callable directly, to get simpler stacktraces (in comparison to call_user_func).
49
        // this assumes that $callable is a properly typed php-callable, which we check in __construct().
50
        return $callable($exception, $inspector, $run);
51
    }
52
}