Test Failed
Push — master ( 8d4319...cae78d )
by 世昌
02:15
created

DebugDumpper::uncaughtError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 4
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace suda\application;
3
4
use suda\framework\Response;
5
6
/**
7
 * 错误Dumpper
8
 */
9
class DebugDumpper
10
{
11
    /**
12
     * 环境内容
13
     *
14
     * @var Response
15
     */
16
    protected $response;
17
18
    /**
19
     * 应用
20
     *
21
     * @var Application
22
     */
23
    protected $application;
24
25
    /**
26
     * 初始化
27
     */
28
    public function __construct(Application $application, Response $response)
29
    {
30
        $this->response = $response;
31
        $this->application = $application;
32
    }
33
34
    /**
35
     * 注册错误处理函数
36
     * @return self
37
     */
38
    public function register()
39
    {
40
        set_exception_handler([$this,'uncaughtException']);
41
        return $this;
42
    }
43
44
    /**
45
     * 异常托管
46
     *
47
     * @param \Throwable $exception
48
     * @return void
49
     */
50
    public function uncaughtException($exception)
51
    {
52
        $this->application->debug()->addIgnoreTraces(__FILE__);
53
        $this->application->debug()->uncaughtException($exception);
54
        if ($this->response->isSended() === false) {
55
            $this->response->sendContent($exception);
56
            $this->response->end();
57
        }
58
    }
59
}
60