ILIAS  release_8 Revision v8.24
class.ilChatroomSetupAgent.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\Setup;
23use ILIAS\UI;
24
26{
27 use Setup\Agent\HasNoNamedObjective;
28
29 private const PORT_MIN = 1;
30 private const PORT_MAX = 65535;
31
33 public static array $LOG_LEVELS = [
34 'emerg',
35 'alert',
36 'crit',
37 'error',
38 'warning',
39 'notice',
40 'info',
41 'debug',
42 'silly'
43 ];
44
46 public static array $INTERVALS = [
47 'days',
48 'weeks',
49 'months',
50 'years'
51 ];
52
53 protected Refinery\Factory $refinery;
54
55 public function __construct(Refinery\Factory $refinery)
56 {
57 $this->refinery = $refinery;
58 }
59
63 public function hasConfig(): bool
64 {
65 return true;
66 }
67
71 public function getConfigInput(Setup\Config $config = null): UI\Component\Input\Field\Input
72 {
73 throw new LogicException("Not yet implemented.");
74 }
75
80 {
81 $levels = self::$LOG_LEVELS;
82 $intervals = self::$INTERVALS;
83
84 return $this->refinery->custom()->transformation(static function ($data) use (
85 $levels,
86 $intervals
87 ): Setup\Config {
88 if (is_null($data)) {
89 return new Setup\NullConfig();
90 }
91
92 $protocol = 'http';
93 if (isset($data['https']) && is_array($data['https']) && $data['https'] !== []) {
94 $protocol = 'https';
95 }
96
97 $deletion_interval = false;
98 if (
99 isset($data['deletion_interval']) &&
100 is_array($data['deletion_interval']) && $data['deletion_interval'] !== []
101 ) {
102 $deletion_interval = true;
103 }
104
105 $ilias_proxy = false;
106 if (isset($data['ilias_proxy']) && is_array($data['ilias_proxy']) && $data['ilias_proxy'] !== []) {
107 $ilias_proxy = true;
108 }
109
110 $client_proxy = false;
111 if (isset($data['client_proxy']) && is_array($data['client_proxy']) && $data['client_proxy'] !== []) {
112 $client_proxy = true;
113 }
114
115 if (isset($data['address']) && !is_string($data['address'])) {
116 throw new InvalidArgumentException(sprintf(
117 '%s is not a valid value for address (must be a string). Please check your config file.',
118 $data['address'],
119 ));
120 }
121
122 if (
123 isset($data['port']) && (
124 !is_numeric($data['port']) ||
125 ((int) $data['port'] < self::PORT_MIN || (int) $data['port'] > self::PORT_MAX)
126 )
127 ) {
128 throw new InvalidArgumentException(sprintf(
129 '%s is not a valid value for port (must be between %s and %s). Please check your config file.',
130 $data['port'] ?? '',
131 self::PORT_MIN,
132 self::PORT_MAX
133 ));
134 }
135
136 if (isset($data['sub_directory']) && !is_string($data['sub_directory'])) {
137 throw new InvalidArgumentException(sprintf(
138 '%s is not a valid value for sub_directory (must be a string). Please check your config file.',
139 $data['sub_directory'],
140 ));
141 }
142
143 if (isset($data['log']) && !is_string($data['log'])) {
144 throw new InvalidArgumentException(sprintf(
145 '%s is not a valid value for log (must be a string). Please check your config file.',
146 $data['log'],
147 ));
148 }
149
150 if (isset($data['error_log']) && !is_string($data['error_log'])) {
151 throw new InvalidArgumentException(sprintf(
152 '%s is not a valid value for error_log (must be a string). Please check your config file.',
153 $data['error_log'],
154 ));
155 }
156
157 if (
158 isset($data['log']) && $data['log'] !== '' &&
159 !in_array((string) ($data['log_level'] ?? ''), $levels, true)
160 ) {
161 throw new InvalidArgumentException(sprintf(
162 '%s is not a valid value for log_level (must be one of: %s). Please check your config file.',
163 $data['log_level'] ?? '',
164 implode(', ', $levels)
165 ));
166 }
167
168 if ($deletion_interval) {
169 if (!in_array($data['deletion_interval']['deletion_unit'] ?? null, $intervals, true)) {
170 throw new InvalidArgumentException(sprintf(
171 '%s is not a valid value for deletion_unit (must be one of: %s). Please check your config file.',
172 $data['deletion_interval']['deletion_unit'] ?? '',
173 implode(', ', $intervals)
174 ));
175 }
176 if (
177 !isset($data['deletion_interval']['deletion_value']) ||
178 !is_numeric($data['deletion_interval']['deletion_value'])
179 ) {
180 throw new InvalidArgumentException(sprintf(
181 '%s is not a valid value for deletion_value. Please check your config file.',
182 $data['deletion_interval']['deletion_value'] ?? ''
183 ));
184 }
185 if (
186 !isset($data['deletion_interval']['deletion_time']) ||
187 !is_string($data['deletion_interval']['deletion_time']) ||
188 !preg_match('/([01][0-9]|[2][0-3]):[0-5][0-9]/', $data['deletion_interval']['deletion_time'])
189 ) {
190 throw new InvalidArgumentException(sprintf(
191 '%s is not a valid value for deletion_time. Please check your config file.',
192 $data['deletion_interval']['deletion_time'] ?? ''
193 ));
194 }
195 }
196
197 return new ilChatroomSetupConfig(
198 $data['address'] ?? '',
199 (int) ($data['port'] ?? 0),
200 $data['sub_directory'] ?? '',
201 $protocol,
202 $data['https']['cert'] ?? '',
203 $data['https']['key'] ?? '',
204 $data['https']['dhparam'] ?? '',
205 $data['log'] ?? '',
206 $data['log_level'] ?? '',
207 $data['error_log'] ?? '',
208 $ilias_proxy,
209 $data['ilias_proxy']['ilias_url'] ?? '',
210 $client_proxy,
211 $data['client_proxy']['client_url'] ?? '',
212 $deletion_interval,
213 $data['deletion_interval']['deletion_unit'] ?? '',
214 (int) ($data['deletion_interval']['deletion_value'] ?? 0),
215 $data['deletion_interval']['deletion_time'] ?? ''
216 );
217 });
218 }
219
223 public function getInstallObjective(Setup\Config $config = null): Setup\Objective
224 {
225 // null would not be valid here, because this agents strictly wants to have
226 // a config.
227 if ($config instanceof Setup\NullConfig) {
229 }
230
232 }
233
237 public function getUpdateObjective(Setup\Config $config = null): Setup\Objective
238 {
239 // null would be valid here, because our user might just not have passed
240 // one during update.
241 if ($config === null || $config instanceof Setup\NullConfig) {
243 }
244
246 }
247
251 public function getBuildArtifactObjective(): Setup\Objective
252 {
254 }
255
259 public function getStatusObjective(Setup\Metrics\Storage $storage): Setup\Objective
260 {
261 return new ilChatroomMetricsCollectedObjective($storage);
262 }
263
267 public function getMigrations(): array
268 {
269 return [];
270 }
271}
Builds data types.
Definition: Factory.php:21
A configuration with no content.
Definition: NullConfig.php:27
A non-objective, nothing to do to achieve it...
getInstallObjective(Setup\Config $config=null)
getUpdateObjective(Setup\Config $config=null)
getStatusObjective(Setup\Metrics\Storage $storage)
__construct(Refinery\Factory $refinery)
getConfigInput(Setup\Config $config=null)
A transformation is a function from one datatype to another.
A agent is some component that performs part of the setup process.
Definition: Agent.php:30
A configuration for the setup.
Definition: Config.php:27
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: ByTrying.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class Factory.