1
|
|
|
<?php |
2
|
|
|
namespace suda\application; |
3
|
|
|
|
4
|
|
|
use suda\application\Resource as ApplicationResource; |
5
|
|
|
use suda\framework\arrayobject\ArrayDotAccess; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* 模块名 |
9
|
|
|
*/ |
10
|
|
|
class Module |
11
|
|
|
{ |
12
|
|
|
const LOADED = 1; |
13
|
|
|
const REACHABLE = 2; |
14
|
|
|
const RUNNING = 3; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* 模块名 |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $name; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* 版本 |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $version; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* 资源路径 |
32
|
|
|
* |
33
|
|
|
* @var ApplicationResource |
34
|
|
|
*/ |
35
|
|
|
protected $resource; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* 状态 |
39
|
|
|
* |
40
|
|
|
* @var int |
41
|
|
|
*/ |
42
|
|
|
protected $status; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* 模块配置 |
46
|
|
|
* |
47
|
|
|
* @var array |
48
|
|
|
*/ |
49
|
|
|
protected $config; |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var array |
54
|
|
|
*/ |
55
|
|
|
protected $property; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* 路径 |
59
|
|
|
* |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
protected $path; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* 创建模块 |
66
|
|
|
* @param string $name |
67
|
|
|
* @param string $version |
68
|
|
|
* @param string $path |
69
|
|
|
* @param string $property |
70
|
|
|
* @param array $config |
71
|
|
|
*/ |
72
|
|
|
public function __construct(string $name, string $version, string $path, array $property, array $config = []) |
73
|
|
|
{ |
74
|
|
|
$this->name = $name; |
75
|
|
|
$this->version = $version; |
76
|
|
|
$this->path = $path; |
77
|
|
|
$this->config = $config; |
78
|
|
|
$this->property = $property; |
79
|
|
|
$this->resource = new ApplicationResource; |
80
|
|
|
$this->status = Module::REACHABLE; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get 版本 |
85
|
|
|
* |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public function getVersion():string |
89
|
|
|
{ |
90
|
|
|
return $this->version; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get 模块名 |
95
|
|
|
* |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
public function getName():string |
99
|
|
|
{ |
100
|
|
|
return $this->name; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* 获取全名 |
105
|
|
|
* |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
public function getFullName():string |
109
|
|
|
{ |
110
|
|
|
return $this->getName().':'.$this->getVersion(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* 获取链接安全名 |
115
|
|
|
* |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public function getUriSafeName():string |
119
|
|
|
{ |
120
|
|
|
return $this->getName().'/'.$this->getVersion(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Get 资源路径 |
125
|
|
|
* |
126
|
|
|
* @return ApplicationResource |
127
|
|
|
*/ |
128
|
|
|
public function getResource():ApplicationResource |
129
|
|
|
{ |
130
|
|
|
return $this->resource; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Set 资源路径 |
135
|
|
|
* |
136
|
|
|
* @param ApplicationResource $resource 资源路径 |
137
|
|
|
* |
138
|
|
|
* @return $this |
139
|
|
|
*/ |
140
|
|
|
public function setResource(ApplicationResource $resource) |
141
|
|
|
{ |
142
|
|
|
$this->resource = $resource; |
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* 设置状态 |
148
|
|
|
* |
149
|
|
|
* @param integer $status |
150
|
|
|
* @return void |
151
|
|
|
*/ |
152
|
|
|
public function setStatus(int $status) |
153
|
|
|
{ |
154
|
|
|
$this->status = $status; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Get 模块配置 |
159
|
|
|
* |
160
|
|
|
* @param string|null $name |
161
|
|
|
* @param mixed $default |
162
|
|
|
* @return mixed |
163
|
|
|
*/ |
164
|
|
|
public function getConfig(string $name = null, $default = null) |
165
|
|
|
{ |
166
|
|
|
if ($name !== null) { |
167
|
|
|
return ArrayDotAccess::get($this->config, $name, $default); |
168
|
|
|
} |
169
|
|
|
return $this->config; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param string|null $name |
174
|
|
|
* @param null $default |
|
|
|
|
175
|
|
|
* @return mixed |
176
|
|
|
*/ |
177
|
|
|
public function getProperty(string $name = null, $default = null) |
178
|
|
|
{ |
179
|
|
|
if ($name !== null) { |
180
|
|
|
return ArrayDotAccess::get($this->property, $name, $default); |
181
|
|
|
} |
182
|
|
|
return $this->property; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @param string $name |
187
|
|
|
*/ |
188
|
|
|
public function setName(string $name): void |
189
|
|
|
{ |
190
|
|
|
$this->name = $name; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param string $version |
195
|
|
|
*/ |
196
|
|
|
public function setVersion(string $version): void |
197
|
|
|
{ |
198
|
|
|
$this->version = $version; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @param array $config |
203
|
|
|
*/ |
204
|
|
|
public function setConfig(array $config): void |
205
|
|
|
{ |
206
|
|
|
$this->config = $config; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @param array $property |
211
|
|
|
*/ |
212
|
|
|
public function setProperty(array $property): void |
213
|
|
|
{ |
214
|
|
|
$this->property = $property; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @param string $path |
219
|
|
|
*/ |
220
|
|
|
public function setPath(string $path): void |
221
|
|
|
{ |
222
|
|
|
$this->path = $path; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @return int |
227
|
|
|
*/ |
228
|
|
|
public function getStatus(): int |
229
|
|
|
{ |
230
|
|
|
return $this->status; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @return string |
235
|
|
|
*/ |
236
|
|
|
public function getPath(): string |
237
|
|
|
{ |
238
|
|
|
return $this->path; |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
|