ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilGSProviderFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
33
38{
42 private ?array $plugin_provider_collections = null;
43 private array $class_loader;
49 protected array $all_providers = [];
50
53
57 public function __construct(private readonly Container $dic)
58 {
59 $this->main_menu_item_information = new ilMMItemInformation();
60 $this->footer_item_information = new ilFooterCustomItemInformation($dic);
62 $this->class_loader = include ilGlobalScreenBuildProviderMapObjective::PATH();
63 $this->component_repository = $this->dic["component.repository"];
64 $this->component_factory = $this->dic["component.factory"];
65 }
66
67 private function initPlugins(): void
68 {
69 if (!is_array($this->plugin_provider_collections)) {
70 $this->plugin_provider_collections = [];
71 foreach ($this->component_repository->getPlugins() as $plugin) {
72 if (!$plugin->isActive()) {
73 continue;
74 }
75 $pl = $this->component_factory->getPlugin($plugin->getId());
76 $this->plugin_provider_collections[] = $pl->getGlobalScreenProviderCollection();
77 }
78 }
79 }
80
81
82 protected function registerInternal(array $providers): void
83 {
84 array_walk(
85 $providers,
86 function (Provider $item): void {
87 $this->all_providers[$item::class] = $item;
88 }
89 );
90 }
91
92
93 public function getMainBarProvider(): array
94 {
95 $providers = [];
96 // Core
97 $this->appendCore($providers, StaticMainMenuProvider::class);
98
99 // Plugins
100 $this->initPlugins();
101 foreach ($this->plugin_provider_collections as $collection) {
102 $provider = $collection->getMainBarProvider();
103 if ($provider) {
104 $providers[] = $provider;
105 }
106 }
107
108 $this->registerInternal($providers);
109
110 return $providers;
111 }
112
113 public function getFooterProvider(): array
114 {
115 $providers = [];
116 // Core
117 $this->appendCore($providers, StaticFooterProvider::class);
118
119 // Plugins
120 // $this->initPlugins();
121 // foreach ($this->plugin_provider_collections as $collection) {
122 // $provider = $collection->getMainBarProvider();
123 // if ($provider) {
124 // $providers[] = $provider;
125 // }
126 // }
127
128 $this->registerInternal($providers);
129
130 return $providers;
131 }
132
133
134 public function getMetaBarProvider(): array
135 {
136 $providers = [];
137 // Core
138 $this->appendCore($providers, StaticMetaBarProvider::class);
139
140 // Plugins
141 $this->initPlugins();
142 foreach ($this->plugin_provider_collections as $collection) {
143 $provider = $collection->getMetaBarProvider();
144 if ($provider) {
145 $providers[] = $provider;
146 }
147 }
148
149 $this->registerInternal($providers);
150
151 return $providers;
152 }
153
154
155 public function getToolProvider(): array
156 {
157 $providers = [];
158 // Core
159 $this->appendCore($providers, DynamicToolProvider::class);
160
161 // Plugins
162 $this->initPlugins();
163 foreach ($this->plugin_provider_collections as $collection) {
164 $provider = $collection->getToolProvider();
165 if ($provider) {
166 $providers[] = $provider;
167 }
168 }
169
170 $this->registerInternal($providers);
171
172 return $providers;
173 }
174
175 public function getModificationProvider(): array
176 {
177 $providers = [];
178 // Core
179 $this->appendCore($providers, ModificationProvider::class);
180
181 // Plugins
182 $this->initPlugins();
183 foreach ($this->plugin_provider_collections as $collection) {
184 $provider = $collection->getModificationProvider();
185 if ($provider) {
186 $providers[] = $provider;
187 }
188 }
189
190 return $providers;
191 }
192
193 public function getNotificationsProvider(): array
194 {
195 $providers = [];
196 // Core
197 $this->appendCore($providers, NotificationProvider::class);
198
199 // Plugins
200 $this->initPlugins();
201 foreach ($this->plugin_provider_collections as $collection) {
202 $provider = $collection->getNotificationProvider();
203 if ($provider) {
204 $providers[] = $provider;
205 }
206 }
207
208 $this->registerInternal($providers);
209
210 return $providers;
211 }
212
213
214 public function getToastsProvider(): array
215 {
216 $providers = [];
217 // Core
218 $this->appendCore($providers, ToastProvider::class);
219
220 // Plugins
221 $this->initPlugins();
222 foreach ($this->plugin_provider_collections as $collection) {
223 $provider = $collection->getToastProvider();
224 if ($provider) {
225 $providers[] = $provider;
226 }
227 }
228
229 $this->registerInternal($providers);
230
231 return $providers;
232 }
233
234
235 private function appendCore(array &$array_of_providers, string $interface): void
236 {
237 foreach ($this->class_loader[$interface] ?? [] as $class_name) {
238 if ($this->isInstanceCreationPossible($class_name)) {
239 try {
240 $array_of_providers[] = new $class_name($this->dic);
241 } catch (Throwable) {
242 }
243 }
244 }
245 }
246
248 {
250 }
251
252 public function getFooterItemInformation(): \ILIAS\GlobalScreen\Scope\Footer\Collector\Information\ItemInformation
253 {
255 }
256
257 public function getProviderByClassName(string $class_name): Provider
258 {
259 if (!$this->isInstanceCreationPossible($class_name) || !$this->isRegistered($class_name)) {
260 throw new LogicException("the GlobalScreen-Provider $class_name is not available");
261 }
262
263 return $this->all_providers[$class_name];
264 }
265
266
267 public function isInstanceCreationPossible(string $class_name): bool
268 {
269 try {
270 return class_exists($class_name);
271 } catch (Throwable) {
272 return false;
273 }
274 }
275
276
277 public function isRegistered(string $class_name): bool
278 {
279 return isset($this->all_providers[$class_name]);
280 }
281}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
registerInternal(array $providers)
isRegistered(string $class_name)
getProviderByClassName(string $class_name)
readonly ItemInformation $main_menu_item_information
isInstanceCreationPossible(string $class_name)
ilComponentFactory $component_factory
readonly ilFooterCustomItemInformation $footer_item_information
__construct(private readonly Container $dic)
@inheritDoc
appendCore(array &$array_of_providers, string $interface)
ilComponentRepository $component_repository
Class ilMMItemInformation.
Readable part of repository interface to ilComponentDataDB.
$dic
Definition: ltiresult.php:33
$provider
Definition: ltitoken.php:80
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.