Passed
Push — master ( cd6927...afac5a )
by 世昌
02:10
created

DebugDumper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A uncaughtException() 0 7 2
A register() 0 4 1
1
<?php
2
namespace suda\application;
3
4
use Exception;
5
use suda\framework\Request;
6
use suda\framework\Response;
7
use Throwable;
8
9
/**
10
 * Class DebugDumper
11
 * @package suda\application
12
 */
13
class DebugDumper
14
{
15
    /**
16
     * 应用
17
     *
18
     * @var Application
19
     */
20
    protected $application;
21
22
    /**
23
     * @var Request
24
     */
25
    protected $request;
26
27
    /**
28
     * @var Response
29
     */
30
    protected $response;
31
32
    /**
33
     * DebugDumper constructor.
34
     * @param Application $application
35
     * @param Request $request
36
     * @param Response $response
37
     */
38
    public function __construct(Application $application, Request $request, Response $response)
39
    {
40
        $this->application = $application;
41
        $this->request = $request;
42
        $this->response = $response;
43
    }
44
45
    /**
46
     * 注册错误处理函数
47
     * @return $this
48
     */
49
    public function register()
50
    {
51
        set_exception_handler([$this,'uncaughtException']);
52
        return $this;
53
    }
54
55
    /**
56
     * 异常托管
57
     *
58
     * @param Throwable $exception
59
     * @return void
60
     * @throws Exception
61
     */
62
    public function uncaughtException($exception)
63
    {
64
        $this->application->debug()->addIgnorePath(__FILE__);
65
        $this->application->debug()->uncaughtException($exception);
66
        if ($this->response->isSend() === false) {
67
            $this->response->sendContent($exception);
68
            $this->response->end();
69
        }
70
    }
71
}
72