ILIAS  release_8 Revision v8.24
class.ilGSProviderFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
32
38{
42 private ?array $plugin_provider_collections = null;
43 private array $class_loader;
44 private Container $dic;
49 protected array $all_providers;
50
53
57 public function __construct(Container $dic)
58 {
59 $this->dic = $dic;
60 $this->main_menu_item_information = new ilMMItemInformation();
62 $this->class_loader = include "Services/GlobalScreen/artifacts/global_screen_providers.php";
63 $this->component_repository = $dic["component.repository"];
64 $this->component_factory = $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
84 protected function registerInternal(array $providers): void
85 {
86 array_walk(
87 $providers,
88 function (Provider $item): void {
89 $this->all_providers[get_class($item)] = $item;
90 }
91 );
92 }
93
97 public function getMainBarProvider(): array
98 {
99 $providers = [];
100 // Core
101 $this->appendCore($providers, StaticMainMenuProvider::class);
102
103 // Plugins
104 $this->initPlugins();
105 foreach ($this->plugin_provider_collections as $collection) {
106 $provider = $collection->getMainBarProvider();
107 if ($provider) {
108 $providers[] = $provider;
109 }
110 }
111
112 $this->registerInternal($providers);
113
114 return $providers;
115 }
116
120 public function getMetaBarProvider(): array
121 {
122 $providers = [];
123 // Core
124 $this->appendCore($providers, StaticMetaBarProvider::class);
125
126 // Plugins
127 $this->initPlugins();
128 foreach ($this->plugin_provider_collections as $collection) {
129 $provider = $collection->getMetaBarProvider();
130 if ($provider) {
131 $providers[] = $provider;
132 }
133 }
134
135 $this->registerInternal($providers);
136
137 return $providers;
138 }
139
143 public function getToolProvider(): array
144 {
145 $providers = [];
146 // Core
147 $this->appendCore($providers, DynamicToolProvider::class);
148
149 // Plugins
150 $this->initPlugins();
151 foreach ($this->plugin_provider_collections as $collection) {
152 $provider = $collection->getToolProvider();
153 if ($provider) {
154 $providers[] = $provider;
155 }
156 }
157
158 $this->registerInternal($providers);
159
160 return $providers;
161 }
162
166 public function getModificationProvider(): array
167 {
168 $providers = [];
169 // Core
170 $this->appendCore($providers, ModificationProvider::class);
171
172 // Plugins
173 $this->initPlugins();
174 foreach ($this->plugin_provider_collections as $collection) {
175 $provider = $collection->getModificationProvider();
176 if ($provider) {
177 $providers[] = $provider;
178 }
179 }
180
181 return $providers;
182 }
183
187 public function getNotificationsProvider(): array
188 {
189 $providers = [];
190 // Core
191 $this->appendCore($providers, NotificationProvider::class);
192
193 // Plugins
194 $this->initPlugins();
195 foreach ($this->plugin_provider_collections as $collection) {
196 $provider = $collection->getNotificationProvider();
197 if ($provider) {
198 $providers[] = $provider;
199 }
200 }
201
202 $this->registerInternal($providers);
203
204 return $providers;
205 }
206
210 public function getToastsProvider(): array
211 {
212 $providers = [];
213 // Core
214 $this->appendCore($providers, ToastProvider::class);
215
216 // Plugins
217 $this->initPlugins();
218 foreach ($this->plugin_provider_collections as $collection) {
219 $provider = $collection->getToastProvider();
220 if ($provider) {
221 $providers[] = $provider;
222 }
223 }
224
225 $this->registerInternal($providers);
226
227 return $providers;
228 }
229
234 private function appendCore(array &$array_of_providers, string $interface): void
235 {
236 foreach ($this->class_loader[$interface] ?? [] as $class_name) {
237 if ($this->isInstanceCreationPossible($class_name)) {
238 try {
239 $array_of_providers[] = new $class_name($this->dic);
240 } catch (Throwable $e) {
241 }
242 }
243 }
244 }
245
250 {
252 }
253
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
269 public function isInstanceCreationPossible(string $class_name): bool
270 {
271 try {
272 return class_exists($class_name);
273 } catch (Throwable $e) {
274 return false;
275 }
276 }
277
281 public function isRegistered(string $class_name): bool
282 {
283 return isset($this->all_providers[$class_name]);
284 }
285}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
Class ilGSProviderFactory.
registerInternal(array $providers)
isRegistered(string $class_name)
@inheritDoc
getProviderByClassName(string $class_name)
@inheritDoc
isInstanceCreationPossible(string $class_name)
@inheritDoc
ilComponentFactory $component_factory
ItemInformation $main_menu_item_information
__construct(Container $dic)
@inheritDoc
appendCore(array &$array_of_providers, string $interface)
ilComponentRepository $component_repository
Class ilMMItemInformation.
Readable part of repository interface to ilComponentDataDB.
$provider
Definition: ltitoken.php:83