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