1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link http://www.newicon.net/neon |
4
|
|
|
* @copyright Copyright (c) 2008 Newicon Ltd |
5
|
|
|
* @license http://www.newicon.net/neon/license/ |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace neon\core; |
9
|
|
|
|
10
|
|
|
use Neon; |
11
|
|
|
use neon\core\db\Migrator; |
12
|
|
|
use \neon\core\helpers\Arr; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Provide common operations for main Application (web application and console Applications) |
16
|
|
|
* |
17
|
|
|
* @property array $apps Store the array configuration of installed community and third party applications |
18
|
|
|
* @property \neon\firefly\App $firefly |
19
|
|
|
* |
20
|
|
|
* @method |
21
|
|
|
*/ |
22
|
|
|
trait ApplicationTrait |
23
|
|
|
{ |
24
|
|
|
public $debug = true; |
25
|
|
|
|
26
|
|
|
public $env = 'dev'; |
27
|
|
|
|
28
|
|
|
public $systemFolderPath = null; // store the systemFolderPath required by neon |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return \neon\firefly\services\fileManager\interfaces\IFileManager; |
32
|
|
|
*/ |
33
|
182 |
|
public function getFirefly() |
34
|
|
|
{ |
35
|
182 |
|
return neon()->getApp('firefly'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return \neon\cms\App |
40
|
|
|
*/ |
41
|
|
|
public function getCms() |
42
|
|
|
{ |
43
|
|
|
return neon()->getApp('cms'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* This is equal to neon()->settings->manager |
48
|
|
|
* @return neon\settings\interfaces\ISettingsManager |
49
|
|
|
*/ |
50
|
6 |
|
public function getSettingsManager() |
51
|
|
|
{ |
52
|
6 |
|
return $this->getSettings()->getSettingsManager(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return \neon\settings\App |
57
|
|
|
*/ |
58
|
6 |
|
public function getSettings() |
59
|
|
|
{ |
60
|
6 |
|
return neon()->getApp('settings'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return \neon\daedalus\App |
65
|
|
|
*/ |
66
|
|
|
public function getDaedalus() |
67
|
|
|
{ |
68
|
|
|
return neon('daedalus'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Alias for Daedalus |
73
|
|
|
* @return \neon\daedalus\App |
74
|
|
|
*/ |
75
|
120 |
|
public function getDds() |
76
|
|
|
{ |
77
|
120 |
|
return neon('dds'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return \neon\dev\App |
82
|
|
|
*/ |
83
|
|
|
public function getDev() |
84
|
|
|
{ |
85
|
|
|
return neon('dev'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return \neon\phoebe\App |
90
|
|
|
*/ |
91
|
|
|
public function getPhoebe() |
92
|
|
|
{ |
93
|
|
|
return neon('phoebe'); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* get the resolved system folder path |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
public function getSystemFolderPath() |
101
|
|
|
{ |
102
|
|
|
return $this->getAlias($this->systemFolderPath); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Dependant function - check if a module exists with the specified name |
107
|
|
|
* @param string $name |
108
|
|
|
* @return boolean |
109
|
|
|
*/ |
110
|
|
|
abstract public function hasModule($name); |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Whether this is a web app |
114
|
|
|
* @return boolean |
115
|
|
|
*/ |
116
|
|
|
abstract public function isWebApp(); |
117
|
|
|
/** |
118
|
|
|
* Defines path aliases. |
119
|
|
|
* This method calls [[Yii::setAlias()]] to register the path aliases. |
120
|
|
|
* This method is provided so that you can define path aliases when configuring a module. |
121
|
|
|
* @property array list of path aliases to be defined. The array keys are alias names |
122
|
|
|
* (must start with `@`) and the array values are the corresponding paths or aliases. |
123
|
|
|
* See [[setAliases()]] for an example. |
124
|
|
|
* @param array $aliases list of path aliases to be defined. The array keys are alias names |
125
|
|
|
* (must start with `@`) and the array values are the corresponding paths or aliases. |
126
|
|
|
* For example, |
127
|
|
|
* |
128
|
|
|
* ```php |
129
|
|
|
* [ |
130
|
|
|
* '@models' => '@app/models', // an existing alias |
131
|
|
|
* '@backend' => __DIR__ . '/../backend', // a directory |
132
|
|
|
* ] |
133
|
|
|
* ``` |
134
|
|
|
*/ |
135
|
|
|
abstract public function setAliases($aliases); |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Retrieves the child module of the specified ID. |
139
|
|
|
* This method supports retrieving both child modules and grand child modules. |
140
|
|
|
* @param string $id module ID (case-sensitive). To retrieve grand child modules, |
141
|
|
|
* use ID path relative to this module (e.g. `admin/content`). |
142
|
|
|
* @param bool $load whether to load the module if it is not yet loaded. |
143
|
|
|
* @return Module|null the module instance, `null` if the module does not exist. |
|
|
|
|
144
|
|
|
* @see hasModule() |
145
|
|
|
*/ |
146
|
|
|
abstract public function getModule($id, $load = true); |
147
|
|
|
abstract function get($id, $throwException = true); |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* One config function to rule them all. |
152
|
|
|
* This function resolves and modifies the config before it is loaded into the neon |
153
|
|
|
* Note: this is run during the preInit step of Neon |
154
|
|
|
* |
155
|
|
|
* @param array $config - we can adjust the config - this variable holds the resolved config |
156
|
|
|
* @return array - the resolved configuration array |
157
|
|
|
*/ |
158
|
|
|
public function resolveConfig(&$config) |
159
|
|
|
{ |
160
|
|
|
$appType = $this->isWebApp() ? 'web' : 'console'; |
161
|
|
|
// get core configs |
162
|
|
|
$common = self::getConfig('@neon/core/config/common.php'); |
163
|
|
|
$app = self::getConfig("@neon/core/config/$appType.php"); |
164
|
|
|
// project overrides (you can override the common and env_*.php config files that are in the core) |
165
|
|
|
// by specifying the config files with the same name inside the root of the projects config folder |
166
|
|
|
$projectCommon = self::getConfig('@config/common.php', false); |
167
|
|
|
$projectConfig = self::getConfig("@config/$appType.php", false); |
168
|
|
|
// not sure we need this - use env() variables in your common config |
169
|
|
|
// $projectEnv = self::getConfig("@config/$appType/env_".YII_ENV.'.php', false); |
170
|
|
|
// merge and create final config |
171
|
|
|
$config = Arr::merge($common, $app, $projectCommon, $projectConfig, $config); |
172
|
|
|
return $this->resolvedConfig = $config; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @var array store the final resolved config used by the app - mainly here for debug purposes |
177
|
|
|
*/ |
178
|
|
|
public $resolvedConfig; |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @var array Store the array configuration of installed community and third party applications |
182
|
|
|
* for example: |
183
|
|
|
* ```php |
184
|
|
|
* [ |
185
|
|
|
* // unique module => app configuration |
186
|
|
|
* 'crm' => [ |
187
|
|
|
* 'class' => '\neon\crm\App', |
188
|
|
|
* 'alias' => [ |
189
|
|
|
* '@newicon/crm' => '@root/newicon/crm' |
190
|
|
|
* ] |
191
|
|
|
* ] |
192
|
|
|
* ] |
193
|
|
|
* ``` |
194
|
|
|
*/ |
195
|
|
|
private $_apps = []; |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @var boolean note that the apps have already been ordered |
199
|
|
|
*/ |
200
|
|
|
private $_appsRequiredOrder = false; |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Get the apps available |
204
|
|
|
* This is ordered by required apps |
205
|
|
|
* @return array |
206
|
|
|
*/ |
207
|
2 |
|
public function getApps() |
208
|
|
|
{ |
209
|
2 |
|
if ($this->_appsRequiredOrder==false) { |
210
|
|
|
$this->orderAppsByRequired($this->_apps, $ordered); |
|
|
|
|
211
|
|
|
$this->setApps($ordered); |
212
|
|
|
$this->_appsRequiredOrder = true; |
213
|
|
|
} |
214
|
2 |
|
return $this->_apps; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* set the apps available |
219
|
|
|
* @param array $apps |
220
|
|
|
*/ |
221
|
|
|
public function setApps($apps) |
222
|
|
|
{ |
223
|
|
|
$this->_apps = $apps; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @var array The core apps array |
228
|
|
|
* Similar array to that of self::$modules and self::$apps |
229
|
|
|
* but this denotes the core apps that cannot be uninstalled |
230
|
|
|
*/ |
231
|
|
|
private $_coreApps = []; |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @var boolean note that the core apps have already been ordered |
235
|
|
|
*/ |
236
|
|
|
private $_coreAppsRequiredOrder = false; |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Get the core apps available |
240
|
|
|
* @return array |
241
|
|
|
*/ |
242
|
2 |
|
public function getCoreApps() |
243
|
|
|
{ |
244
|
2 |
|
if ($this->_coreAppsRequiredOrder==false) { |
245
|
|
|
$this->orderAppsByRequired($this->_coreApps, $ordered); |
|
|
|
|
246
|
|
|
$this->setCoreApps($ordered); |
247
|
|
|
$this->_coreAppsRequiredOrder = true; |
248
|
|
|
} |
249
|
2 |
|
return $this->_coreApps; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Get all core and user apps |
254
|
|
|
* @return array |
255
|
|
|
*/ |
256
|
|
|
public function getAllApps() |
257
|
|
|
{ |
258
|
|
|
return array_merge($this->getCoreApps(), $this->getApps()); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Set the core apps available |
263
|
|
|
* @param array $coreApps |
264
|
|
|
*/ |
265
|
|
|
public function setCoreApps($coreApps) |
266
|
|
|
{ |
267
|
|
|
$this->_coreApps = $coreApps; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Get a config array from a config path |
272
|
|
|
* Can specify a yii style alias. |
273
|
|
|
* Set the $required parameter to false to return an empty array if the config file does not exist |
274
|
|
|
* |
275
|
|
|
* @param string $path full Yii style alias (@config/path/config.php) or file path string to the config file |
276
|
|
|
* @param boolean $required whether the config is required, will throw an exception if the file does not exist |
277
|
|
|
* @throws \Exception if a config file does not return an array or the config file can not be found and $required is true |
278
|
|
|
* |
279
|
|
|
* @return array |
280
|
|
|
*/ |
281
|
|
|
public static function getConfig($path, $required=true) |
282
|
|
|
{ |
283
|
|
|
$file = Neon::getAlias($path); |
284
|
|
|
$fileExists = file_exists($file); |
|
|
|
|
285
|
|
|
// The file does NOT exist but it IS required |
286
|
|
|
if (!$fileExists && $required) { |
287
|
|
|
// exceptions thrown at this stage create white screens of doom |
288
|
|
|
dp('The config file alias: "'.$path.'" can not be found. File path: "'.$file.'". This config file is required.'); |
289
|
|
|
throw new \Exception('The config file alias: "'.$path.'" can not be found. File path: "'.$file.'". This config file is required.'); |
290
|
|
|
} |
291
|
|
|
// The file does NOT exist and it is NOT required |
292
|
|
|
if (!$fileExists && !$required){ |
293
|
|
|
// the config is not required so we can just return an empty array |
294
|
|
|
return []; |
295
|
|
|
} |
296
|
|
|
$config = require $file; |
297
|
|
|
if (!is_array($config)) { |
298
|
|
|
// exceptions thrown at this stage create white screens of doom |
299
|
|
|
dp('The file "'.$file.'" is not a valid config file. It must return an array'); |
300
|
|
|
throw new \Exception('The file "'.$file.'" is not a valid config file. It must return an array'); |
301
|
|
|
} |
302
|
|
|
return $config; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* This function loads and bootstraps the community and third party apps |
307
|
|
|
* This has to be called in the initial bootup script |
308
|
|
|
* Seperating loading of the core and community apps means that we can easily |
309
|
|
|
* fall back to a robust core state |
310
|
|
|
* It is safe to call on the database at this point. |
311
|
|
|
* Check user log in credentials etc. You may want to only load certain apps based on users |
312
|
|
|
* specific user crednetials. Note this is not called automatically during start up ($app->run()) |
313
|
|
|
* This currently has to be called seperately |
314
|
|
|
* |
315
|
|
|
* @return void |
316
|
|
|
*/ |
317
|
|
|
public function registerAllApps() |
318
|
|
|
{ |
319
|
|
|
Neon::beginProfile('Application::registerAllApps', 'neon\Application'); |
320
|
|
|
// We CAN access the database at this point. |
321
|
|
|
// This would be useful to get the current list of apps installed / enabled |
322
|
|
|
// This may delegate to a core Store App. Or App Store. |
323
|
|
|
// This would simply return the the config |
324
|
|
|
// However we should not burden the system with loading or knowing about |
325
|
|
|
// all apps on every request! |
326
|
|
|
$apps = []; |
327
|
|
|
|
328
|
|
|
if (file_exists(Neon::getAlias('@config/apps.php'))) { |
|
|
|
|
329
|
|
|
$apps = require Neon::getAlias('@config/apps.php'); |
330
|
|
|
} |
331
|
|
|
// the custom apps, will override the core apps, |
332
|
|
|
// core apps are simply apps defined in the common config $this->apps |
333
|
|
|
// which exist on the apps key after the preInitilization |
334
|
|
|
// meaning it would be possible to override an entire core module |
335
|
|
|
// such as the user, or admin module. |
336
|
|
|
// Load Additional App Modules |
337
|
|
|
$this->setApps(Arr::merge($this->getApps(), $apps)); |
338
|
|
|
// remove disabled apps |
339
|
|
|
|
340
|
|
|
$this->registerApps($this->getApps()); |
341
|
|
|
$this->bootstrapApps($this->getApps()); |
342
|
|
|
Neon::endProfile('Application::registerAllApps', 'neon\Application'); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* Sets many apps |
347
|
|
|
* @see $this->registerApp() |
348
|
|
|
* @param array $apps |
349
|
|
|
* |
350
|
|
|
* @return void |
351
|
|
|
*/ |
352
|
|
|
public function registerApps($apps) |
353
|
|
|
{ |
354
|
|
|
foreach($apps as $name => $config) { |
355
|
|
|
$this->registerApp($name, $config); |
356
|
|
|
} |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* Bootstrap apps |
361
|
|
|
* @param array $apps |
362
|
|
|
*/ |
363
|
|
|
public function bootstrapApps($apps) |
364
|
|
|
{ |
365
|
|
|
foreach ($apps as $app => $config) { |
366
|
|
|
$this->bootstrapApp($app, $config); |
367
|
|
|
} |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* Bootstrap the app |
372
|
|
|
* |
373
|
|
|
* @param string $app The app name |
374
|
|
|
* @param array $config The app config array - must contain a class key |
375
|
|
|
*/ |
376
|
|
|
public function bootstrapApp($app, $config) |
377
|
|
|
{ |
378
|
|
|
if (isset($config['enabled']) && $config['enabled'] == false) { |
379
|
|
|
return; |
380
|
|
|
} |
381
|
|
|
\Neon::beginProfileTickerBomb($profiletoken = $config['class'].'::bootstrap', "★ $app"); |
382
|
|
|
// tell the module to bootstrap |
383
|
|
|
$this->getApp($app)->setup(); |
384
|
|
|
\Neon::endProfileTickerBomb($profiletoken, "★ $app", 0.050); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
/** |
388
|
|
|
* Loads an individual app. |
389
|
|
|
* This performs the function of registering the app with the current Application |
390
|
|
|
* It sets up an alias so the App class can be found and registers this with the modules property |
391
|
|
|
* @param string $name The app name |
392
|
|
|
* @param array $config a configuration array |
393
|
|
|
* @throws \Exception when a module name conflicts with a core module name |
394
|
|
|
* |
395
|
|
|
* @return void |
396
|
|
|
*/ |
397
|
|
|
public function registerApp($name, $config) |
398
|
|
|
{ |
399
|
|
|
if (isset($config['enabled']) && $config['enabled'] == false) { |
400
|
|
|
return; |
401
|
|
|
} |
402
|
|
|
// A way of creating aliases to Apps |
403
|
|
|
// this allows you to use the namespace hub/crm for the classes. |
404
|
|
|
// but it could live anywhere. |
405
|
|
|
// for example '@newicon/crm' => '@root/modules/community/crm' |
406
|
|
|
if (isset($config['alias']) && !empty($config['alias'])) { |
407
|
|
|
$this->setAliases($config['alias']); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
// make sure there is no name clash with a core module |
411
|
|
|
if (array_key_exists($name, $this->modules)) { |
412
|
|
|
throw new \Exception('A core module exists with this name, "'.$name.'" and cannot be overridden'); |
413
|
|
|
} |
414
|
|
|
$this->setModule($name, $config); |
415
|
|
|
|
416
|
|
|
// set up any alternatives for this |
417
|
|
|
if (isset($config['appAliases'])) |
418
|
|
|
$this->setModuleAliases($name, $config['appAliases']); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* Get a neon app |
423
|
|
|
* alternative syntax for @see getApp() |
424
|
|
|
* |
425
|
|
|
* @alias getApp |
426
|
|
|
* @param string $name the unique app name |
427
|
|
|
* @return \neon\core\BaseApp | null |
428
|
|
|
*/ |
429
|
2 |
|
public function app($name) |
430
|
|
|
{ |
431
|
2 |
|
return $this->getApp($name); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* Get a neon app |
436
|
|
|
* example usage: |
437
|
|
|
* ``` |
438
|
|
|
* $userApp = neon()->getApp('user'); |
439
|
|
|
* ``` |
440
|
|
|
* @param string $name the unique app name |
441
|
|
|
* @return \neon\core\BaseApp | null |
442
|
|
|
*/ |
443
|
324 |
|
public function getApp($name) |
444
|
|
|
{ |
445
|
324 |
|
if ($name === 'neon') return $this; |
446
|
324 |
|
$module = $this->getModuleFromName($name); |
447
|
324 |
|
return $this->getModule($module); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* If an app exists |
452
|
|
|
* @param string $name |
453
|
|
|
* @return boolean |
454
|
|
|
*/ |
455
|
|
|
public function hasApp($name) |
456
|
|
|
{ |
457
|
|
|
return $this->hasModule($name); |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
/** |
461
|
|
|
* Return an array of neon Apps |
462
|
|
|
* This gets all core and user defined apps |
463
|
|
|
* |
464
|
|
|
* @return \neon\core\BaseApp[] an array of App objects indexed by their name |
465
|
|
|
*/ |
466
|
2 |
|
public function getActiveApps() |
467
|
|
|
{ |
468
|
2 |
|
$apps = array_merge($this->getCoreApps(), $this->getApps()); |
469
|
2 |
|
$ret = []; |
470
|
2 |
|
foreach($apps as $app => $config) { |
471
|
2 |
|
$appObject = $this->getApp($app); |
472
|
|
|
// apps that are disabled will return null |
473
|
2 |
|
if ($appObject !== null) |
474
|
2 |
|
$ret[$app] = $this->getApp($app); |
475
|
|
|
} |
476
|
2 |
|
return $ret; |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* order a set of apps by their requires so we can install them correctly |
481
|
|
|
* @param array $apps the set of apps |
482
|
|
|
* @param array $ordered the ordered set of apps |
483
|
|
|
* @param array $read the set of already read apps (to prevent circular references) |
484
|
|
|
* |
485
|
|
|
* @return void |
486
|
|
|
*/ |
487
|
2 |
|
public function orderAppsByRequired($apps, &$ordered = null, &$read = null) |
488
|
|
|
{ |
489
|
2 |
|
static $initialApps = null; |
490
|
2 |
|
if ($ordered == null) |
491
|
2 |
|
$initialApps = $apps; |
492
|
2 |
|
$ordered = $ordered == null ? [] : $ordered; |
493
|
2 |
|
$read = $read == null ? [] : $read; |
494
|
2 |
|
foreach ($apps as $key=>$app) { |
495
|
2 |
|
$read[$key] = true; |
496
|
2 |
|
if (!empty($app['requires'])) { |
497
|
2 |
|
$requires = explode(',', $app['requires']); |
498
|
2 |
|
$required = []; |
499
|
2 |
|
foreach ($requires as $r) { |
500
|
2 |
|
$r = trim($r); |
501
|
|
|
// prevent circular references breaking the system |
502
|
2 |
|
if (!array_key_exists($r, $read)) |
503
|
2 |
|
$required[$r] = $initialApps[$r]; |
504
|
|
|
} |
505
|
2 |
|
if (count($required)) { |
506
|
2 |
|
$this->orderAppsByRequired($required, $ordered, $read); |
507
|
|
|
} |
508
|
|
|
} |
509
|
2 |
|
if (!array_key_exists($key, $ordered)) |
510
|
2 |
|
$ordered[$key] = $app; |
511
|
|
|
} |
512
|
2 |
|
} |
513
|
|
|
|
514
|
|
|
/** |
515
|
|
|
* Gets the main neon database that holds all accounts and tenant information |
516
|
|
|
* @return null|object |
517
|
|
|
*/ |
518
|
|
|
public function getNeonDb() |
519
|
|
|
{ |
520
|
|
|
return $this->get('db'); |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* Get the alias key to this module (App) |
525
|
|
|
* The alias sets up the autoloading |
526
|
|
|
* |
527
|
|
|
* @return mixed |
528
|
|
|
*/ |
529
|
|
|
public function getClassAlias() |
530
|
|
|
{ |
531
|
|
|
return '@' . str_replace(['\\', 'Application'], ['/', ''], get_called_class()); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* An alias function to \Neon::getAlias() |
536
|
|
|
* @see \Neon::getAlias |
537
|
|
|
* @param string $alias |
538
|
|
|
* @param bool $throwException whether to throw an exception |
539
|
|
|
* |
540
|
|
|
* @return bool|string |
541
|
|
|
*/ |
542
|
168 |
|
public function getAlias($alias, $throwException = true) |
543
|
|
|
{ |
544
|
168 |
|
return \Neon::getAlias($alias, $throwException); |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
/** |
548
|
|
|
* Whether the app is in dev mode |
549
|
|
|
* |
550
|
|
|
* @return boolean |
551
|
|
|
*/ |
552
|
2 |
|
public function isDevMode() |
553
|
|
|
{ |
554
|
2 |
|
return $this->env == 'dev'; |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
/** |
558
|
|
|
* The install specific to the core apps (admin, user, settings, etc) |
559
|
|
|
* @return void |
560
|
|
|
*/ |
561
|
|
|
public function installCore() |
562
|
|
|
{ |
563
|
|
|
foreach ($this->getCoreApps() as $appName => $config) { |
564
|
|
|
$app = $this->getModule($appName); |
565
|
|
|
$app->install(); |
566
|
|
|
} |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
/** |
570
|
|
|
* Run the install function of each app |
571
|
|
|
* @return void |
572
|
|
|
*/ |
573
|
|
|
public function installApps() |
574
|
|
|
{ |
575
|
|
|
foreach ($this->getApps() as $appName => $config) { |
576
|
|
|
$app = $this->getApp($appName); |
577
|
|
|
$app->install(); |
578
|
|
|
} |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
/** |
582
|
|
|
* Install the core and all registered apps |
583
|
|
|
* @return void |
584
|
|
|
*/ |
585
|
|
|
public function install() |
586
|
|
|
{ |
587
|
|
|
$this->installCore(); |
588
|
|
|
$this->installApps(); |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
/** |
592
|
|
|
* @return string neon version number |
593
|
|
|
*/ |
594
|
|
|
public function getVersion() |
595
|
|
|
{ |
596
|
|
|
return \Neon::getVersion(); |
597
|
|
|
} |
598
|
|
|
|
599
|
|
|
/** |
600
|
|
|
* @return string yii version number |
601
|
|
|
*/ |
602
|
|
|
public function getYiiVersion() |
603
|
|
|
{ |
604
|
|
|
return \Neon::getYiiVersion(); |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
/** |
608
|
|
|
* Return the total execution time |
609
|
|
|
* |
610
|
|
|
* @return float |
611
|
|
|
*/ |
612
|
|
|
public function getExecutionTime() |
613
|
|
|
{ |
614
|
|
|
return microtime(true) - NEON_START; |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
/** |
618
|
|
|
* Get an array of available neon version numbers |
619
|
|
|
* @return array of version number strings - from oldest to newest |
620
|
|
|
*/ |
621
|
|
|
public function getNeonVersions() |
622
|
|
|
{ |
623
|
|
|
return neon()->cacheArray->getOrSet('neon_versions', function() { |
624
|
|
|
try { |
625
|
|
|
$client = new \GuzzleHttp\Client(); |
626
|
|
|
$res = $client->request('GET', 'https://neon.newicon.net/api/versions/', ['connect_timeout' => 2]); |
627
|
|
|
$versions = json_decode((string) $res->getBody()); |
628
|
|
|
} catch(\Exception $e) { |
629
|
|
|
$versions = []; |
630
|
|
|
} |
631
|
|
|
return $versions; |
632
|
|
|
}); |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
/** |
636
|
|
|
* Get an array of version numbers greater than the current version number |
637
|
|
|
* ordered from oldest to newest. Latest neon version is end(neon()->getNeonVersionsNewer()) |
638
|
|
|
* @return array - empty array if there are no available neon version upgrades |
639
|
|
|
*/ |
640
|
|
|
public function getNeonVersionsNewer() |
641
|
|
|
{ |
642
|
|
|
$versions = $this->getNeonVersions(); |
643
|
|
|
$newerVersion = []; |
644
|
|
|
$neonVersion = neon()->getVersion(); |
645
|
|
|
foreach($versions as $v) { |
646
|
|
|
if (version_compare($v, $neonVersion, '>')) { |
647
|
|
|
$newerVersion[] = $v; |
648
|
|
|
} |
649
|
|
|
} |
650
|
|
|
return $newerVersion; |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
/** |
654
|
|
|
* Get the latest neon version available |
655
|
|
|
* @return string|false the version string or false on failure |
656
|
|
|
*/ |
657
|
|
|
public function getNeonVersionLatest() |
658
|
|
|
{ |
659
|
|
|
$versions = $this->getNeonVersions(); |
660
|
|
|
return end($versions); |
661
|
|
|
} |
662
|
|
|
|
663
|
|
|
public function isLatestNeonVersion() |
664
|
|
|
{ |
665
|
|
|
$versions = $this->getNeonVersions(); |
666
|
|
|
return empty($versions); |
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
/** |
670
|
|
|
* Set of aliases to modules either for backward compatibility or |
671
|
|
|
* for convenient short cuts. |
672
|
|
|
*/ |
673
|
|
|
private static $_moduleAliases; |
674
|
|
|
|
675
|
|
|
/** |
676
|
|
|
* Set up the aliases to a particular module |
677
|
|
|
* @param string $name the name of the app |
678
|
|
|
* @param array $aliases any aliases for the app |
679
|
|
|
*/ |
680
|
|
|
private function setModuleAliases($name, $aliases) |
681
|
|
|
{ |
682
|
|
|
foreach($aliases as $alias) |
683
|
|
|
static::$_moduleAliases[$alias] = $name; |
684
|
|
|
} |
685
|
|
|
|
686
|
|
|
/** |
687
|
|
|
* Returns the name for the app. If the alias is the name it returns that |
688
|
|
|
* otherwise it converts the alias to the actual name |
689
|
|
|
* @param string $alias the name to check |
690
|
|
|
* @return string the app name |
691
|
|
|
*/ |
692
|
324 |
|
private function getModuleFromName($name) |
693
|
|
|
{ |
694
|
324 |
|
return (isset(static::$_moduleAliases[$name]) ? static::$_moduleAliases[$name] : $name); |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
/** |
698
|
|
|
* Loop through each app and get all php classes within the app in a particular |
699
|
|
|
* folder or/and implementing a particular class/interface |
700
|
|
|
* @param string $subPath - search within a app subdirectory [default=''] meaning all directories |
701
|
|
|
* @param string $instanceOf - a string defining a class or interface that the classes must implement or be |
702
|
|
|
* @return array indexed by the app name to a list of valid classes |
703
|
|
|
*/ |
704
|
|
|
public function getAppClasses($subPath='', $instanceOf=false) |
705
|
|
|
{ |
706
|
|
|
profile_begin('neon:getAppClasses'); |
707
|
|
|
foreach (neon()->getAllApps() as $key => $config) { |
708
|
|
|
$app = neon()->getApp($key); |
709
|
|
|
// disabled apps wil return null |
710
|
|
|
if ($app === null) continue; |
711
|
|
|
$classes[$key] = $app->getClasses('form/fields', $instanceOf); |
712
|
|
|
} |
713
|
|
|
profile_end('neon:getAppClasses'); |
714
|
|
|
return $classes; |
|
|
|
|
715
|
|
|
} |
716
|
|
|
|
717
|
|
|
} |
718
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths