ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilComponentBuildPluginInfoObjective.php
Go to the documentation of this file.
1 <?php
2 
20 use ILIAS\Setup;
21 
22 class ilComponentBuildPluginInfoObjective extends Setup\Artifact\BuildArtifactObjective
23 {
24  protected const BASE_PATH = "./Customizing/global/plugins/";
25  protected const PLUGIN_PHP = "plugin.php";
26  protected const PLUGIN_CLASS_FILE = "classes/class.il%sPlugin.php";
27 
28  public function getArtifactPath(): string
29  {
30  return \ilArtifactComponentRepository::PLUGIN_DATA_PATH;
31  }
32 
33 
34  public function build(): Setup\Artifact
35  {
36  $data = [];
37  foreach (["Modules", "Services"] as $type) {
38  $components = $this->scanDir(static::BASE_PATH . $type);
39  foreach ($components as $component) {
40  if ($this->isDotFile($component)
41  || ! $this->isDir(static::BASE_PATH . "$type/$component")) {
42  continue;
43  }
44  $slots = $this->scanDir(static::BASE_PATH . "$type/$component");
45  foreach ($slots as $slot) {
46  if ($this->isDotFile($slot)
47  || ! $this->isDir(static::BASE_PATH . "$type/$component/$slot")) {
48  continue;
49  }
50  $plugins = $this->scanDir(static::BASE_PATH . "$type/$component/$slot");
51  foreach ($plugins as $plugin) {
52  if ($this->isDotFile($plugin)
53  || ! $this->isDir(static::BASE_PATH . "$type/$component/$slot/$plugin")) {
54  continue;
55  }
56  $this->addPlugin($data, $type, $component, $slot, $plugin);
57  }
58  }
59  }
60  }
61  return new Setup\Artifact\ArrayArtifact($data);
62  }
63 
64  protected function addPlugin(array &$data, string $type, string $component, string $slot, string $plugin): void
65  {
66  $plugin_path = $this->buildPluginPath($type, $component, $slot, $plugin);
67  $plugin_php = $plugin_path . static::PLUGIN_PHP;
68  if (!$this->fileExists($plugin_php)) {
69  throw new \RuntimeException(
70  "Cannot read $plugin_php."
71  );
72  }
73 
74  $plugin_class = $plugin_path . sprintf(static::PLUGIN_CLASS_FILE, $plugin);
75  if (!$this->fileExists($plugin_class)) {
76  throw new \RuntimeException(
77  "Cannot read $plugin_class."
78  );
79  }
80 
81  require_once($plugin_php);
82  if (!isset($id)) {
83  throw new \InvalidArgumentException("$plugin does not define \$id");
84  }
85  if (!isset($version)) {
86  throw new \InvalidArgumentException("$plugin does not define \$version");
87  }
88  if (!isset($ilias_min_version)) {
89  throw new \InvalidArgumentException("$plugin does not define \$ilias_min_version");
90  }
91  if (!isset($ilias_max_version)) {
92  throw new \InvalidArgumentException("$plugin does not define \$ilias_max_version");
93  }
94 
95  if (isset($data[$id])) {
96  throw new \RuntimeException(
97  "Plugin with id $id already exists."
98  );
99  }
100 
101  $data[$id] = [
102  $type,
103  $component,
104  $slot,
105  $plugin,
106  $version,
109  $responsible ?? "",
110  $responsible_mail ?? "",
111  $learning_progress ?? null,
112  $supports_export ?? null,
113  $supports_cli_setup ?? null
114  ];
115  }
116 
120  protected function scanDir(string $dir): array
121  {
122  if (!file_exists($dir)) {
123  return [];
124  }
125  $result = scandir($dir);
126  return array_values(array_diff($result, [".", ".."]));
127  }
128 
129  protected function fileExists(string $path): bool
130  {
131  return file_exists($path) && is_file($path);
132  }
133 
134  protected function isDir(string $dir): bool
135  {
136  return file_exists($dir) && is_dir($dir);
137  }
138 
139  protected function isDotFile(string $file): bool
140  {
141  return (substr($file, 0, 1) === '.');
142  }
143 
144  protected function buildPluginPath(string $type, string $component, string $slot, string $plugin): string
145  {
146  return static::BASE_PATH . "$type/$component/$slot/$plugin/";
147  }
148 }
$ilias_max_version
Definition: plugin.php:26
$responsible
Definition: plugin.php:27
$learning_progress
Definition: plugin.php:29
$ilias_min_version
Definition: plugin.php:25
$path
Definition: ltiservices.php:32
$responsible_mail
Definition: plugin.php:28
$supports_export
Definition: plugin.php:30
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)
$version
Definition: plugin.php:24