ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilGSProviderFactory.php
Go to the documentation of this file.
1 <?php
2 
13 
19 {
20 
28  private $class_loader;
32  private $dic;
40  protected $all_providers;
41 
45  public function __construct(Container $dic)
46  {
47  $this->dic = $dic;
48  $this->main_menu_item_information = new ilMMItemInformation();
49  $this->class_loader = include "Services/GlobalScreen/artifacts/global_screen_providers.php";
50  }
51 
52  private function initPlugins() : void
53  {
54  if (!is_array($this->plugin_provider_collections)) {
55  $this->plugin_provider_collections = [];
56  foreach (ilPluginAdmin::getGlobalScreenProviderCollections() as $collection) {
57  $this->plugin_provider_collections[] = $collection;
58  }
59  }
60  }
61 
65  protected function registerInternal(array $providers)
66  {
67  array_walk(
68  $providers,
69  function (Provider $item) {
70  $this->all_providers[get_class($item)] = $item;
71  }
72  );
73  }
74 
78  public function getMainBarProvider() : array
79  {
80  $providers = [];
81  // Core
82  $this->appendCore($providers, StaticMainMenuProvider::class);
83 
84  // Plugins
85  $this->initPlugins();
86  foreach ($this->plugin_provider_collections as $collection) {
87  $provider = $collection->getMainBarProvider();
88  if ($provider) {
89  $providers[] = $provider;
90  }
91  }
92 
93  $this->registerInternal($providers);
94 
95  return $providers;
96  }
97 
101  public function getMetaBarProvider() : array
102  {
103  $providers = [];
104  // Core
105  $this->appendCore($providers, StaticMetaBarProvider::class);
106 
107  // Plugins
108  $this->initPlugins();
109  foreach ($this->plugin_provider_collections as $collection) {
110  $provider = $collection->getMetaBarProvider();
111  if ($provider) {
112  $providers[] = $provider;
113  }
114  }
115 
116  $this->registerInternal($providers);
117 
118  return $providers;
119  }
120 
124  public function getToolProvider() : array
125  {
126  $providers = [];
127  // Core
128  $this->appendCore($providers, DynamicToolProvider::class);
129 
130  // Plugins
131  $this->initPlugins();
132  foreach ($this->plugin_provider_collections as $collection) {
133  $provider = $collection->getToolProvider();
134  if ($provider) {
135  $providers[] = $provider;
136  }
137  }
138 
139  $this->registerInternal($providers);
140 
141  return $providers;
142  }
143 
147  public function getModificationProvider() : array
148  {
149  $providers = [];
150  // Core
151  $this->appendCore($providers, ModificationProvider::class);
152 
153  // Plugins
154  $this->initPlugins();
155  foreach ($this->plugin_provider_collections as $collection) {
156  $provider = $collection->getModificationProvider();
157  if ($provider) {
158  $providers[] = $provider;
159  }
160  }
161 
162  return $providers;
163  }
164 
168  public function getNotificationsProvider() : array
169  {
170  $providers = [];
171  // Core
172  $this->appendCore($providers, NotificationProvider::class);
173 
174  // Plugins
175  $this->initPlugins();
176  foreach ($this->plugin_provider_collections as $collection) {
177  $provider = $collection->getNotificationProvider();
178  if ($provider) {
179  $providers[] = $provider;
180  }
181  }
182 
183  $this->registerInternal($providers);
184 
185  return $providers;
186  }
187 
192  private function appendPlugins(array &$array_of_core_providers, string $interface) : void
193  {
194  // Plugins
195  static $plugin_providers;
196 
197  $plugin_providers = $plugin_providers ?? ilPluginAdmin::getAllGlobalScreenProviders();
198 
199  foreach ($plugin_providers as $provider) {
200  if (is_a($provider, $interface)) {
201  $array_of_core_providers[] = $provider;
202  }
203  }
204  }
205 
210  private function appendCore(array &$array_of_providers, string $interface) : void
211  {
212  foreach ($this->class_loader[$interface] as $class_name) {
213  if ($this->isInstanceCreationPossible($class_name)) {
214  try {
215  $array_of_providers[] = new $class_name($this->dic);
216  } catch (Throwable $e) {
217  $i = $e;
218  }
219  }
220  }
221  }
222 
227  {
229  }
230 
234  public function getProviderByClassName(string $class_name) : Provider
235  {
236  if (!$this->isInstanceCreationPossible($class_name) || !$this->isRegistered($class_name)) {
237  throw new \LogicException("the GlobalScreen-Provider $class_name is not available");
238  }
239 
240  return $this->all_providers[$class_name];
241  }
242 
246  public function isInstanceCreationPossible(string $class_name) : bool
247  {
248  try {
249  return class_exists($class_name) && $class_name !== ilPluginGlobalScreenNullProvider::class;
250  } catch (\Throwable $e) {
251  return false;
252  }
253  }
254 
258  public function isRegistered(string $class_name) : bool
259  {
260  return isset($this->all_providers[$class_name]);
261  }
262 }
Class ilGSProviderFactory.
Class ilMMItemInformation.
static getAllGlobalScreenProviders()
isRegistered(string $class_name)
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:18
appendPlugins(array &$array_of_core_providers, string $interface)
registerInternal(array $providers)
isInstanceCreationPossible(string $class_name)
getProviderByClassName(string $class_name)
appendCore(array &$array_of_providers, string $interface)
$i
Definition: metadata.php:24