ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
class.ilComponentBuildPluginInfoObjective.php
Go to the documentation of this file.
1 <?php
2 
19 use ILIAS\Setup;
20 
21 class ilComponentBuildPluginInfoObjective extends Setup\Artifact\BuildArtifactObjective
22 {
23  protected const BASE_PATH = "./public/Customizing/global/plugins/";
24  protected const PLUGIN_PHP = "plugin.php";
25  protected const PLUGIN_CLASS_FILE = "classes/class.il%sPlugin.php";
26 
27 
28  public function getArtifactName(): string
29  {
30  return "plugin_data";
31  }
32 
33  public function build(): Setup\Artifact
34  {
35  $data = [];
36  foreach (['Modules', 'Services'] as $type) {
37  $base_path = static::BASE_PATH . $type . '/';
38  if (! $this->isDir($base_path)) {
39  continue;
40  }
41  $components = $this->scanDir($base_path);
42  foreach ($components as $component) {
43  if ($this->isDotFile($component)
44  || ! $this->isDir($base_path . "$component")) {
45  continue;
46  }
47  $slots = $this->scanDir($base_path . "$component");
48  foreach ($slots as $slot) {
49  if ($this->isDotFile($slot)
50  || ! $this->isDir($base_path . "$component/$slot")) {
51  continue;
52  }
53  $plugins = $this->scanDir($base_path . "$component/$slot");
54  foreach ($plugins as $plugin) {
55  if ($this->isDotFile($plugin)
56  || ! $this->isDir($base_path . "$component/$slot/$plugin")) {
57  continue;
58  }
59  $this->addPlugin($data, $type, $component, $slot, $plugin);
60  }
61  }
62  }
63  }
64  return new Setup\Artifact\ArrayArtifact($data);
65  }
66 
67  protected function addPlugin(array &$data, string $type, string $component, string $slot, string $plugin): void
68  {
69  $plugin_path = $this->buildPluginPath($type, $component, $slot, $plugin);
70  $plugin_php = $plugin_path . static::PLUGIN_PHP;
71  if (!$this->fileExists($plugin_php)) {
72  throw new \RuntimeException(
73  "Cannot read $plugin_php."
74  );
75  }
76 
77  $plugin_class = $plugin_path . sprintf(static::PLUGIN_CLASS_FILE, $plugin);
78  if (!$this->fileExists($plugin_class)) {
79  throw new \RuntimeException(
80  "Cannot read $plugin_class."
81  );
82  }
83 
84  require_once($plugin_php);
85  if (!isset($id)) {
86  throw new \InvalidArgumentException("$plugin does not define \$id");
87  }
88  if (!isset($version)) {
89  throw new \InvalidArgumentException("$plugin does not define \$version");
90  }
91  if (!isset($ilias_min_version)) {
92  throw new \InvalidArgumentException("$plugin does not define \$ilias_min_version");
93  }
94  if (!isset($ilias_max_version)) {
95  throw new \InvalidArgumentException("$plugin does not define \$ilias_max_version");
96  }
97 
98  if (isset($data[$id])) {
99  throw new \RuntimeException(
100  "Plugin with id $id already exists."
101  );
102  }
103 
104  $data[$id] = [
105  $type,
106  $component,
107  $slot,
108  $plugin,
109  $version,
112  $responsible ?? "",
113  $responsible_mail ?? "",
116  $supports_cli_setup ?? null
117  ];
118  }
119 
123  protected function scanDir(string $dir): array
124  {
125  if (!file_exists($dir)) {
126  return [];
127  }
128  $result = scandir($dir);
129  return array_values(array_diff($result, [".", ".."]));
130  }
131 
132  protected function fileExists(string $path): bool
133  {
134  return file_exists($path) && is_file($path);
135  }
136 
137  protected function isDir(string $dir): bool
138  {
139  return file_exists($dir) && is_dir($dir);
140  }
141 
142  protected function isDotFile(string $file): bool
143  {
144  return (substr($file, 0, 1) === '.');
145  }
146 
147  protected function buildPluginPath(string $type, string $component, string $slot, string $plugin): string
148  {
149  return static::BASE_PATH . "$type/$component/$slot/$plugin/";
150  }
151 }
$supports_export
Definition: plugin.php:30
$responsible_mail
Definition: plugin.php:28
$version
Definition: plugin.php:24
$ilias_max_version
Definition: plugin.php:26
$path
Definition: ltiservices.php:29
$components
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$ilias_min_version
Definition: plugin.php:25
$learning_progress
Definition: plugin.php:29
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildPluginPath(string $type, string $component, string $slot, string $plugin)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
An artifact is some file that is build on demand per installation and is not shipped with the ILIAS s...
Definition: Artifact.php:27
addPlugin(array &$data, string $type, string $component, string $slot, string $plugin)
$responsible
Definition: plugin.php:27