Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Foundation\Exceptions;
4
 
5
use Illuminate\Support\Traits\ReflectsClosures;
6
use Throwable;
7
 
8
class ReportableHandler
9
{
10
    use ReflectsClosures;
11
 
12
    /**
13
     * The underlying callback.
14
     *
15
     * @var callable
16
     */
17
    protected $callback;
18
 
19
    /**
20
     * Indicates if reporting should stop after invoking this handler.
21
     *
22
     * @var bool
23
     */
24
    protected $shouldStop = false;
25
 
26
    /**
27
     * Create a new reportable handler instance.
28
     *
29
     * @param  callable  $callback
30
     * @return void
31
     */
32
    public function __construct(callable $callback)
33
    {
34
        $this->callback = $callback;
35
    }
36
 
37
    /**
38
     * Invoke the handler.
39
     *
40
     * @param  \Throwable  $e
41
     * @return bool
42
     */
43
    public function __invoke(Throwable $e)
44
    {
45
        $result = call_user_func($this->callback, $e);
46
 
47
        if ($result === false) {
48
            return false;
49
        }
50
 
51
        return ! $this->shouldStop;
52
    }
53
 
54
    /**
55
     * Determine if the callback handles the given exception.
56
     *
57
     * @param  \Throwable  $e
58
     * @return bool
59
     */
60
    public function handles(Throwable $e)
61
    {
62
        foreach ($this->firstClosureParameterTypes($this->callback) as $type) {
63
            if (is_a($e, $type)) {
64
                return true;
65
            }
66
        }
67
 
68
        return false;
69
    }
70
 
71
    /**
72
     * Indicate that report handling should stop after invoking this callback.
73
     *
74
     * @return $this
75
     */
76
    public function stop()
77
    {
78
        $this->shouldStop = true;
79
 
80
        return $this;
81
    }
82
}