Passed
Push — master ( c061fa...c1447f )
by 世昌
02:22
created

Context::instance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
namespace nebula;
3
4
use nebula\application\Route;
5
use nebula\application\Request;
6
use nebula\application\Debugger;
7
use nebula\application\Application;
8
use nebula\component\loader\Loader;
9
use nebula\application\config\Config;
10
use nebula\application\response\Response;
11
use nebula\component\cacheable\CacheInterface;
12
13
/**
14
 * 应用
15
 *
16
 */
17
class Context
18
{
19
    /**
20
     * 应用路径
21
     *
22
     * @var string
23
     */
24
    protected $path;
25
26
    /**
27
     * 数据路径
28
     *
29
     * @var string
30
     */
31
    protected $dataPath;
32
33
    /**
34
     * 类加载器
35
     *
36
     * @var Loader
37
     */
38
    protected $classLoader;
39
40
    /**
41
     * 调试工具
42
     *
43
     * @var Debugger
44
     */
45
    protected $debugger;
46
47
    /**
48
     * 路由
49
     *
50
     * @var Route
51
     */
52
    protected $route;
53
    
54
    /**
55
     * 配置信息
56
     *
57
     * @var Config
58
     */
59
    protected $config;
60
61
    /**
62
     * 应用引用程序
63
     *
64
     * @var Application
65
     */
66
    protected $application;
67
68
    /**
69
     * 请求封装
70
     *
71
     * @var Request
72
     */
73
    protected $request;
74
75
    /**
76
     * 缓存
77
     *
78
     * @var CacheInterface
79
     */
80
    protected $cache;
81
82
    /**
83
     * 响应
84
     *
85
     * @var Response
86
     */
87
    protected $response;
88
    
89
    /**
90
     * 静态实例
91
     *
92
     * @var self
93
     */
94
    protected static $instance;
95
96
97
    /**
98
     * 返回实例
99
     *
100
     * @return self
101
     */
102
    public static function instance()
103
    {
104
        if (isset(static::$instance)) {
105
            return static::$instance;
106
        }
107
        return static::$instance = new static;
108
    }
109
    
110
    /**
111
     * Get 类加载器
112
     *
113
     * @return  Loader
114
     */
115
    public function getClassLoader()
116
    {
117
        return $this->classLoader;
118
    }
119
120
    /**
121
     * Set 类加载器
122
     *
123
     * @param  Loader  $classLoader  类加载器
124
     *
125
     * @return  self
126
     */
127
    public function setClassLoader(Loader $classLoader)
128
    {
129
        $this->classLoader = $classLoader;
130
131
        return $this;
132
    }
133
134
    /**
135
     * Get 调试工具
136
     *
137
     * @return  Debugger
138
     */
139
    public function getDebugger()
140
    {
141
        return $this->debugger;
142
    }
143
144
    /**
145
     * Set 调试工具
146
     *
147
     * @param  Debugger  $debugger  调试工具
148
     *
149
     * @return  self
150
     */
151
    public function setDebugger(Debugger $debugger)
152
    {
153
        $this->debugger = $debugger;
154
155
        return $this;
156
    }
157
158
159
    /**
160
     * Get 配置信息
161
     *
162
     * @return  Config
163
     */
164
    public function getConfig()
165
    {
166
        return $this->config;
167
    }
168
169
    /**
170
     * Set 配置信息
171
     *
172
     * @param  Config  $config  配置信息
173
     *
174
     * @return  self
175
     */
176
    public function setConfig(Config $config)
177
    {
178
        $this->config = $config;
179
180
        return $this;
181
    }
182
183
    /**
184
     * Get 路由
185
     *
186
     * @return  Route
187
     */
188
    public function getRoute()
189
    {
190
        return $this->route;
191
    }
192
193
    /**
194
     * Set 路由
195
     *
196
     * @param  Route  $route  路由
197
     *
198
     * @return  self
199
     */
200
    public function setRoute(Route $route)
201
    {
202
        $this->route = $route;
203
204
        return $this;
205
    }
206
 
207
208
    /**
209
     * Get 应用引用程序
210
     *
211
     * @return  Application
212
     */
213
    public function getApplication()
214
    {
215
        return $this->application;
216
    }
217
218
    /**
219
     * Set 应用引用程序
220
     *
221
     * @param  Application  $application  应用引用程序
222
     *
223
     * @return  self
224
     */
225
    public function setApplication(Application $application)
226
    {
227
        $this->application = $application;
228
229
        return $this;
230
    }
231
232
    /**
233
     * Get 请求封装
234
     *
235
     * @return  Request
236
     */
237
    public function getRequest()
238
    {
239
        return $this->request;
240
    }
241
242
    /**
243
     * Set 请求封装
244
     *
245
     * @param  Request  $request  请求封装
246
     *
247
     * @return  self
248
     */
249
    public function setRequest(Request $request)
250
    {
251
        $this->request = $request;
252
253
        return $this;
254
    }
255
256
    /**
257
     * Get 缓存
258
     *
259
     * @return  CacheInterface
260
     */ 
261
    public function getCache()
262
    {
263
        return $this->cache;
264
    }
265
266
    /**
267
     * Set 缓存
268
     *
269
     * @param  CacheInterface  $cache  缓存
270
     *
271
     * @return  self
272
     */ 
273
    public function setCache(CacheInterface $cache)
274
    {
275
        $this->cache = $cache;
276
277
        return $this;
278
    }
279
280
    /**
281
     * Get 响应
282
     *
283
     * @return  Response
284
     */ 
285
    public function getResponse()
286
    {
287
        return $this->response;
288
    }
289
290
    /**
291
     * Set 响应
292
     *
293
     * @param  Response  $response  响应
294
     *
295
     * @return  self
296
     */ 
297
    public function setResponse(Response $response)
298
    {
299
        $this->response = $response;
300
301
        return $this;
302
    }
303
304
    /**
305
     * 是否是Debug模式
306
     *
307
     * @return boolean
308
     */
309
    public function isDebug():bool {
310
        return defined('NEBULA_DEBUG') ? constant('NEBULA_DEBUG') : false;
311
    }
312
}
313