|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace neon\utilities; |
|
4
|
|
|
|
|
5
|
|
|
use neon\utilities\utils\DbInfo; |
|
6
|
|
|
use neon\utilities\utils\PhpInfo; |
|
7
|
|
|
use neon\utilities\utils\SystemReport; |
|
8
|
|
|
use neon\utilities\utils\Updates; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* The neon core settings app class |
|
12
|
|
|
* |
|
13
|
|
|
* @property \neon\settings\services\SettingsManager $settingsManager |
|
14
|
|
|
*/ |
|
15
|
|
|
class App extends \neon\core\BaseApp |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @event RegisterUtilitiesEvent The event that is triggered when registering utilities |
|
19
|
|
|
* |
|
20
|
|
|
* Utility types must implement [[IUtility]]. [[\neon\utilities\utils\IUtility]] provides a base implementation. |
|
21
|
|
|
* --- |
|
22
|
|
|
* ```php |
|
23
|
|
|
* use neon\utilities\events\RegisterUtils; |
|
24
|
|
|
* use neon\utilities\App as Utility; |
|
25
|
|
|
* use yii\base\Event; |
|
26
|
|
|
* |
|
27
|
|
|
* Event::on(Utility::class, Utility::RegisterUtils, function(Register $event) { |
|
28
|
|
|
* $event->utils[] = MyUtilityType::class; |
|
29
|
|
|
* }); |
|
30
|
|
|
* |
|
31
|
|
|
* // or |
|
32
|
|
|
* |
|
33
|
|
|
* neon()->getApp('utilities')->onRegisterUtils(function(Register $event) { |
|
34
|
|
|
* $event->utils[] = MyUtilityType::class; |
|
35
|
|
|
* }); |
|
36
|
|
|
* ``` |
|
37
|
|
|
*/ |
|
38
|
|
|
const EVENT_REGISTER_UTILITIES = 'registerUtilities'; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Returns all available utility type classes. |
|
42
|
|
|
* |
|
43
|
|
|
* @return string[] |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getAllUtilities(): array |
|
46
|
|
|
{ |
|
47
|
|
|
$utils = [ |
|
48
|
|
|
Updates::class, |
|
49
|
|
|
SystemReport::class, |
|
50
|
|
|
PhpInfo::class, |
|
51
|
|
|
DbInfo::class, |
|
52
|
|
|
Cache::class, |
|
|
|
|
|
|
53
|
|
|
DeprecationErrors::class, |
|
|
|
|
|
|
54
|
|
|
DbBackup::class, |
|
|
|
|
|
|
55
|
|
|
Migrations::class, |
|
|
|
|
|
|
56
|
|
|
Errors::class |
|
|
|
|
|
|
57
|
|
|
]; |
|
58
|
|
|
|
|
59
|
|
|
$event = new RegisterUtils(['utils' => $utils]); |
|
|
|
|
|
|
60
|
|
|
$this->trigger(self::EVENT_REGISTER_UTILITIES, $event); |
|
61
|
|
|
|
|
62
|
|
|
return $event->utils; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Returns all utility type classes that the user has permission to use. |
|
67
|
|
|
* |
|
68
|
|
|
* @return string[] |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getAuthorizedUtilities(): array |
|
71
|
|
|
{ |
|
72
|
|
|
$utilityTypes = []; |
|
73
|
|
|
|
|
74
|
|
|
foreach ($this->getAllUtilities() as $class) { |
|
75
|
|
|
if ($this->checkAuthorization($class)) { |
|
76
|
|
|
$utilityTypes[] = $class; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return $utilityTypes; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Returns whether the current user is authorized to use a given utility. |
|
85
|
|
|
* |
|
86
|
|
|
* @param string $class The utility class |
|
87
|
|
|
* @return bool |
|
88
|
|
|
*/ |
|
89
|
|
|
public function checkAuthorization(string $class): bool |
|
90
|
|
|
{ |
|
91
|
|
|
/** @var string|IUtilitiy $class */ |
|
92
|
|
|
return neon()->getUser()->checkPermission('utility:' . $class::id()); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Returns a utility class by its ID |
|
97
|
|
|
* |
|
98
|
|
|
* @param string $id |
|
99
|
|
|
* @return string|null |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getUtilityTypeById(string $id) |
|
102
|
|
|
{ |
|
103
|
|
|
foreach ($this->getAllUtilityTypes() as $class) { |
|
|
|
|
|
|
104
|
|
|
/** @var UtilityInterface $class */ |
|
105
|
|
|
if ($class::id() === $id) { |
|
106
|
|
|
return $class; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
return null; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Shorthand method to register an event |
|
115
|
|
|
* |
|
116
|
|
|
* @param Callable $handler |
|
117
|
|
|
*/ |
|
118
|
|
|
public function onRegisterUtils($handler) |
|
119
|
|
|
{ |
|
120
|
|
|
$this->on(self::EVENT_REGISTER_UTILITIES, $handler); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @inheritdoc |
|
125
|
|
|
*/ |
|
126
|
|
|
public function getMenu() |
|
127
|
|
|
{ |
|
128
|
|
|
return [ |
|
129
|
|
|
'label' => $this->getName(), |
|
130
|
|
|
'order' => 2000, |
|
131
|
|
|
'url' => ['/utilities/index/index'], |
|
132
|
|
|
'visible' => neon()->user->is('neon-administrator'), |
|
133
|
|
|
'active' => is_route('/utilities*') |
|
134
|
|
|
]; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @inheritdoc |
|
139
|
|
|
*/ |
|
140
|
|
|
public function getName() |
|
141
|
|
|
{ |
|
142
|
|
|
return 'Utilities'; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
} |
|
146
|
|
|
|
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