ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.SkillGUIRequest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 namespace ILIAS\Skill\Service;
23 
24 use ILIAS\HTTP;
25 use ILIAS\Refinery;
26 
34 {
35  protected HTTP\Services $http;
36  protected Refinery\Factory $refinery;
37  protected ?array $passed_query_params = null;
38  protected ?array $passed_post_data = null;
39 
44  public function __construct(
45  HTTP\Services $http,
46  Refinery\Factory $refinery,
47  ?array $passed_query_params = null,
48  ?array $passed_post_data = null
49  ) {
50  $this->http = $http;
51  $this->refinery = $refinery;
52  $this->passed_query_params = $passed_query_params;
53  $this->passed_post_data = $passed_post_data;
54  }
55 
59  protected function int(string $key): int
60  {
61  $t = $this->refinery->kindlyTo()->int();
62  return (int) ($this->get($key, $t) ?? 0);
63  }
64 
69  protected function intArray(string $key): array
70  {
71  if (!$this->isArray($key)) {
72  return [];
73  }
74  $t = $this->refinery->custom()->transformation(
75  static function (array $arr): array {
76  // keep keys(!), transform all values to int
77  return array_map('intval', $arr);
78  }
79  );
80  return (array) ($this->get($key, $t) ?? []);
81  }
82 
86  protected function str(string $key): string
87  {
88  $t = $this->refinery->kindlyTo()->string();
89  return \ilUtil::stripSlashes((string) ($this->get($key, $t) ?? ""));
90  }
91 
96  protected function strArray(string $key): array
97  {
98  if (!$this->isArray($key)) {
99  return [];
100  }
101  $t = $this->refinery->custom()->transformation(
102  static function (array $arr): array {
103  // keep keys(!), transform all values to string
104  return array_map(
105  static function ($v): string {
106  return \ilUtil::stripSlashes((string) $v);
107  },
108  $arr
109  );
110  }
111  );
112  return (array) ($this->get($key, $t) ?? []);
113  }
114 
118  protected function bool(string $key): bool
119  {
120  $t = $this->refinery->kindlyTo()->bool();
121  return (bool) ($this->get($key, $t) ?? false);
122  }
123 
128  protected function boolArray(string $key): array
129  {
130  if (!$this->isArray($key)) {
131  return [];
132  }
133  $t = $this->refinery->custom()->transformation(
134  static function (array $arr): array {
135  // keep keys(!), transform all values to bool
136  return array_map('boolval', $arr);
137  }
138  );
139  return (array) ($this->get($key, $t) ?? []);
140  }
141 
145  protected function isArray(string $key): bool
146  {
147  if ($this->passed_query_params === null && $this->passed_post_data === null) {
148  $no_transform = $this->refinery->identity();
149  $w = $this->http->wrapper();
150  if ($w->post()->has($key)) {
151  return is_array($w->post()->retrieve($key, $no_transform));
152  }
153  if ($w->query()->has($key)) {
154  return is_array($w->query()->retrieve($key, $no_transform));
155  }
156  }
157  if (isset($this->passed_post_data[$key])) {
158  return is_array($this->passed_post_data[$key]);
159  }
160  if (isset($this->passed_query_params[$key])) {
161  return is_array($this->passed_query_params[$key]);
162  }
163  return false;
164  }
165 
171  protected function get(string $key, Refinery\Transformation $t)
172  {
173  if ($this->passed_query_params === null && $this->passed_post_data === null) {
174  $w = $this->http->wrapper();
175  if ($w->post()->has($key)) {
176  return $w->post()->retrieve($key, $t);
177  }
178  if ($w->query()->has($key)) {
179  return $w->query()->retrieve($key, $t);
180  }
181  }
182  if (isset($this->passed_post_data[$key])) {
183  return $t->transform($this->passed_post_data[$key]);
184  }
185  if (isset($this->passed_query_params[$key])) {
186  return $t->transform($this->passed_query_params[$key]);
187  }
188  return null;
189  }
190 
194  protected function getIds(): array
195  {
196  return $this->intArray("id");
197  }
198 
202  protected function getTableIds(string $key): array
203  {
204  return $this->strArray($key);
205  }
206 
207  protected function getTableAction(string $key): string
208  {
209  return $this->str($key);
210  }
211 
215  protected function getInterruptiveItemIds(): array
216  {
217  return $this->intArray("interruptive_items");
218  }
219 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(HTTP\Services $http, Refinery\Factory $refinery, ?array $passed_query_params=null, ?array $passed_post_data=null)
Query params and post data parameters are used for testing.
intArray(string $key)
get integer array kindly
Skill gui global request wrapper.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
boolArray(string $key)
get bool array kindly
string $key
Consumer key/client ID value.
Definition: System.php:193
str(string $key)
get string parameter kindly
isArray(string $key)
Check if parameter is an array.
int(string $key)
get integer parameter kindly
strArray(string $key)
get string array kindly
bool(string $key)
get bool parameter kindly
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...