Total Complexity | 8 |
Total Lines | 109 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | class PHPContext |
||
12 | { |
||
13 | /** |
||
14 | * PHP自动加载 |
||
15 | * |
||
16 | * @var Loader |
||
17 | */ |
||
18 | protected $loader; |
||
19 | |||
20 | /** |
||
21 | * 全局配置 |
||
22 | * |
||
23 | * @var Config |
||
24 | */ |
||
25 | protected $config; |
||
26 | |||
27 | |||
28 | /** |
||
29 | * 创建PHP环境 |
||
30 | * |
||
31 | * @param Config $config |
||
32 | * @param Loader $loader |
||
33 | */ |
||
34 | public function __construct(Config $config, Loader $loader) |
||
35 | { |
||
36 | $this->loader = $loader; |
||
37 | $this->config = $config; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * 获取加载器 |
||
42 | * |
||
43 | * @return Loader |
||
44 | */ |
||
45 | public function loader():Loader |
||
48 | } |
||
49 | |||
50 | |||
51 | /** |
||
52 | * 获取配置 |
||
53 | * |
||
54 | * @return Config |
||
55 | */ |
||
56 | public function config():Config |
||
57 | { |
||
58 | return $this->config; |
||
59 | } |
||
60 | |||
61 | |||
62 | /** |
||
63 | * 获取配置信息 |
||
64 | * |
||
65 | * @param string $name |
||
66 | * @param mixed $default |
||
67 | * @return mixed |
||
68 | */ |
||
69 | public function conf(string $name, $default = null) |
||
70 | { |
||
71 | return $this->config->get($name, $default); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Get PHP自动加载 |
||
76 | * |
||
77 | * @return Loader |
||
78 | */ |
||
79 | public function getLoader() |
||
80 | { |
||
81 | return $this->loader; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Set PHP自动加载 |
||
86 | * |
||
87 | * @param Loader $loader PHP自动加载 |
||
88 | * |
||
89 | * @return self |
||
90 | */ |
||
91 | public function setLoader(Loader $loader) |
||
92 | { |
||
93 | $this->loader = $loader; |
||
94 | |||
95 | return $this; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Get 全局配置 |
||
100 | * |
||
101 | * @return Config |
||
102 | */ |
||
103 | public function getConfig() |
||
104 | { |
||
105 | return $this->config; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Set 全局配置 |
||
110 | * |
||
111 | * @param Config $config 全局配置 |
||
112 | * |
||
113 | * @return self |
||
114 | */ |
||
115 | public function setConfig(Config $config) |
||
120 | } |
||
121 | } |
||
122 |