Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.php
More file actions
Latest commit
269 lines (239 loc) · 7.41 KB
/
Copy pathModule.php
File metadata and controls
269 lines (239 loc) · 7.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<?php
namespaceXanweb\Module;
useConcrete\Core\Application\Application;
useConcrete\Core\Entity\Package;
useConcrete\Core\Foundation\ClassAliasList;
useConcrete\Core\Foundation\Service\ProviderList;
useConcrete\Core\Package\PackageasPackageController;
useConcrete\Core\Package\PackageService;
useConcrete\Core\Routing\RouteListInterface;
useConcrete\Core\Support\Facade\ApplicationasFacadeApp;
useConcrete\Core\Support\Facade\Route;
useIlluminate\Support\Str;
useSymfony\Component\EventDispatcher\EventSubscriberInterface;
useXanweb\Module\Asset\Provider;
/**
* @method static string getPackagePath() @see \Concrete\Core\Package\Package::getPackagePath()
* @method static string getRelativePath() @see \Concrete\Core\Package\Package::getRelativePath()
*/
abstractclass Module implements ModuleInterface
{
privatestaticApplication$app;
/**
* The resolved controller instances.
*
* @var array
*/
privatestaticarray$resolvedPackController = [];
/**
* Class to be used Statically.
*/
privatefunction__construct()
{
}
/**
* Handle dynamic, static calls to the controller.
*
* @param string $method
* @param array $args
*
* @return mixed
*/
publicstaticfunction__callStatic($method, $args)
{
returnself::controller()->$method(...$args);
}
/**
* {@inheritdoc}
*
* @see ModuleInterface::pkg()
*/
publicstaticfunctionpkg(): Package
{
returnself::controller()->getPackageEntity();
}
/**
* {@inheritdoc}
*
* @see ModuleInterface::boot()
*/
publicstaticfunctionboot(): void
{
// Register Class Aliases
if (($aliases = static::getClassAliases()) !== []) {
ClassAliasList::getInstance()->registerMultiple($aliases);
}
$app = self::app();
// Register Service Providers
if (($providers = static::getServiceProviders()) !== []) {
$app->make(ProviderList::class)->registerProviders($providers);
}
// Register Route Lists
if (($routeListClasses = static::getRoutesClasses()) !== []) {
$router = Route::getFacadeRoot();
foreach ($routeListClassesas$routeListClass) {
if (is_subclass_of($routeListClass, RouteListInterface::class)) {
$router->loadRouteList($app->make($routeListClass));
} else {
self::throwInvalidClassRuntimeException('getRoutesClasses', $routeListClass, RouteListInterface::class);
}
}
}
// Register Asset Providers
$assetProviders = static::getAssetProviders();
foreach ($assetProvidersas$assetProviderClass) {
if (is_subclass_of($assetProviderClass, Provider::class)) {
$app->make($assetProviderClass, ['package' => static::pkg()])->register();
} else {
self::throwInvalidClassRuntimeException('getAssetProviders', $assetProviderClass, Provider::class);
}
}
// Register Event Subscribers
if (($evtSubscriberClasses = static::getEventSubscribers()) !== []) {
$director = $app->make('director');
foreach ($evtSubscriberClassesas$evtSubscriberClass) {
if (is_subclass_of($evtSubscriberClass, EventSubscriberInterface::class)) {
$director->addSubscriber($app->make($evtSubscriberClass));
} else {
self::throwInvalidClassRuntimeException('getEventSubscribers', $evtSubscriberClass, EventSubscriberInterface::class);
}
}
}
//register console commands
if (($consoleCmdClasses = static::getConsoleCmds()) !== []) {
foreach ($consoleCmdClassesas$cmdClass) {
if ($app->has("console")) {
$app->make("console")->add($app->make($cmdClass));
}
}
}
}
publicstaticfunctionisInstalled(): bool
{
try {
returnstatic::pkg()->isPackageInstalled();
} catch (\Throwable$e) {
returnfalse;
}
}
/**
* Get Database Config.
*
* @param string|null $key
* @param mixed $default
*
* @return \Concrete\Core\Config\Repository\Liaison|mixed
*/
finalpublicstaticfunctiongetConfig(?string$key = null, $default = null)
{
$config = self::controller()->getDatabaseConfig();
if ($key !== null) {
return$config->get($key, $default);
}
return$config;
}
/**
* Get File Config.
*
* @param string|null $key
* @param mixed $default
*
* @return \Concrete\Core\Config\Repository\Liaison|mixed
*/
finalpublicstaticfunctiongetFileConfig(?string$key = null, $default = null)
{
$config = self::controller()->getFileConfig();
if ($key !== null) {
return$config->get($key, $default);
}
return$config;
}
/**
* Classes to be registered as aliases in \Concrete\Core\Foundation\ClassAliasList.
*
* @return array
*/
protectedstaticfunctiongetClassAliases(): array
{
return [
static::getPackageAlias() => static::class,
];
}
/**
* Get Package Alias.
*
* @return string
*/
protectedstaticfunctiongetPackageAlias(): string
{
return Str::studly(static::pkgHandle());
}
/**
* Get Service Providers Class Names.
*
* @return string[]
*/
protectedstaticfunctiongetServiceProviders(): array
{
return [];
}
/**
* Get Classes names for RouteList, must be an instance of \Concrete\Core\Routing\RouteListInterface.
*
* @return string[]
*/
protectedstaticfunctiongetRoutesClasses(): array
{
return [];
}
/**
* AssetProviders should be an instance of \Xanweb\Module\Asset\Provider.
*
* @return string[]
*/
protectedstaticfunctiongetAssetProviders(): array
{
return [];
}
/**
* Event Subscribers should be an instance of \Symfony\Component\EventDispatcher\EventSubscriberInterface.
*
* @return string[]
*/
protectedstaticfunctiongetEventSubscribers(): array
{
return [];
}
/**
* @param string $make [optional]
*
* @return Application|object
*/
protectedstaticfunctionapp($make = null)
{
if (!isset(self::$app)) {
self::$app = FacadeApp::getFacadeApplication();
}
if ($make !== null) {
returnself::$app->make($make);
}
returnself::$app;
}
privatestaticfunctionthrowInvalidClassRuntimeException(string$relatedMethod, $targetClass, string$requiredClass): void
{
thrownew \RuntimeException(t('%s:%s - `%s` should be an instance of `%s`', static::class, $relatedMethod, (string)$targetClass, $requiredClass));
}
privatestaticfunctioncontroller(): PackageController
{
$pkgHandle = static::pkgHandle();
returnself::$resolvedPackController[$pkgHandle] ??= self::app(PackageService::class)->getClass($pkgHandle);
}
/**
* return list of CLI command class list
* @return string[]
*/
protectedstaticfunctiongetConsoleCmds(): array
{
return [];
}
}