Passed
Push — master ( 9cdc70...50a759 )
by 世昌
01:58
created

Application::getResource()   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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace nebula\application;
3
4
use Exception;
5
use nebula\NebulaApplication;
6
use nebula\application\Resource;
7
use nebula\component\loader\Path;
8
use nebula\application\config\Config;
9
use nebula\component\request\Request;
10
11
/**
12
 * 应用程序加载器
13
 *
14
 * 负责加载
15
 */
16
class Application
17
{
18
    /**
19
     * 应用
20
     *
21
     * @var NebulaApplication
22
     */
23
    protected $nebula;
24
25
    /**
26
     * 资源管理
27
     *
28
     * @var Resource
29
     */
30
    protected $resource;
31
32
    
33
    public function setNebula(NebulaApplication $application)
34
    {
35
        $this->nebula = $application;
36
    }
37
38
39
    /**
40
     * Get 资源管理
41
     *
42
     * @return  Resource
43
     */
44
    public function getResource()
45
    {
46
        return $this->resource;
47
    }
48
49
    /**
50
     * Set 资源管理
51
     *
52
     * @param  Resource  $resource  资源管理
53
     *
54
     * @return  self
55
     */
56
    public function setResource(Resource $resource)
57
    {
58
        $this->resource = $resource;
59
60
        return $this;
61
    }
62
63
    /**
64
     * Get 应用
65
     *
66
     * @return  NebulaApplication
67
     */
68
    public function getNebula()
69
    {
70
        return $this->nebula;
71
    }
72
73
    /**
74
     * 初始化
75
     *
76
     * @return void
77
     */
78
    public function initiation()
79
    {
80
        $this->initResource();
81
    }
82
83
    /**
84
     * 处理请求
85
     *
86
     * @param Request $request
87
     * @return boolean
88
     */
89
    public function onRequest(Request $request): bool {
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

89
    public function onRequest(/** @scrutinizer ignore-unused */ Request $request): bool {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
90
        return false;
91
    }
92
93
    /**
94
     * 处理异常
95
     *
96
     * @param Exception $exception
97
     * @return boolean
98
     */
99
    public function onException(Exception $exception): bool {
0 ignored issues
show
Unused Code introduced by
The parameter $exception is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

99
    public function onException(/** @scrutinizer ignore-unused */ Exception $exception): bool {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
100
        return false;
101
    }
102
103
    protected function initResource()
104
    {
105
        $resource = new Resource;
106
        foreach ($this->getNebula()->getConfig()->get('app.resource') as $path) {
107
            if (Path::isRelativePath($path)) {
108
                $path = Resource::getPathByRelativedPath($path, constant('NEBULA_APP'));
109
            }
110
            $resource->addResourcePath($path);
111
        }
112
        $this->setResource($resource);
113
    }
114
}
115