ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.SkillGUIRequest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Skill\Service;
22
23use ILIAS\HTTP;
25
33{
35 protected Refinery\Factory $refinery;
36 protected ?array $passed_query_params = null;
37 protected ?array $passed_post_data = null;
38
43 public function __construct(
46 ?array $passed_query_params = null,
47 ?array $passed_post_data = null
48 ) {
49 $this->http = $http;
50 $this->refinery = $refinery;
51 $this->passed_query_params = $passed_query_params;
52 $this->passed_post_data = $passed_post_data;
53 }
54
58 protected function int(string $key): int
59 {
60 $t = $this->refinery->kindlyTo()->int();
61 return (int) ($this->get($key, $t) ?? 0);
62 }
63
68 protected function intArray(string $key): array
69 {
70 if (!$this->isArray($key)) {
71 return [];
72 }
73 $t = $this->refinery->custom()->transformation(
74 static function (array $arr): array {
75 // keep keys(!), transform all values to int
76 return array_map('intval', $arr);
77 }
78 );
79 return (array) ($this->get($key, $t) ?? []);
80 }
81
85 protected function str(string $key): string
86 {
87 $t = $this->refinery->kindlyTo()->string();
88 return \ilUtil::stripSlashes((string) ($this->get($key, $t) ?? ""));
89 }
90
95 protected function strArray(string $key): array
96 {
97 if (!$this->isArray($key)) {
98 return [];
99 }
100 $t = $this->refinery->custom()->transformation(
101 static function (array $arr): array {
102 // keep keys(!), transform all values to string
103 return array_map(
104 static function ($v): string {
105 return \ilUtil::stripSlashes((string) $v);
106 },
107 $arr
108 );
109 }
110 );
111 return (array) ($this->get($key, $t) ?? []);
112 }
113
117 protected function bool(string $key): bool
118 {
119 $t = $this->refinery->kindlyTo()->bool();
120 return (bool) ($this->get($key, $t) ?? false);
121 }
122
127 protected function boolArray(string $key): array
128 {
129 if (!$this->isArray($key)) {
130 return [];
131 }
132 $t = $this->refinery->custom()->transformation(
133 static function (array $arr): array {
134 // keep keys(!), transform all values to bool
135 return array_map('boolval', $arr);
136 }
137 );
138 return (array) ($this->get($key, $t) ?? []);
139 }
140
144 protected function isArray(string $key): bool
145 {
146 if ($this->passed_query_params === null && $this->passed_post_data === null) {
147 $no_transform = $this->refinery->identity();
148 $w = $this->http->wrapper();
149 if ($w->post()->has($key)) {
150 return is_array($w->post()->retrieve($key, $no_transform));
151 }
152 if ($w->query()->has($key)) {
153 return is_array($w->query()->retrieve($key, $no_transform));
154 }
155 }
156 if (isset($this->passed_post_data[$key])) {
157 return is_array($this->passed_post_data[$key]);
158 }
159 if (isset($this->passed_query_params[$key])) {
160 return is_array($this->passed_query_params[$key]);
161 }
162 return false;
163 }
164
170 protected function get(string $key, Refinery\Transformation $t)
171 {
172 if ($this->passed_query_params === null && $this->passed_post_data === null) {
173 $w = $this->http->wrapper();
174 if ($w->post()->has($key)) {
175 return $w->post()->retrieve($key, $t);
176 }
177 if ($w->query()->has($key)) {
178 return $w->query()->retrieve($key, $t);
179 }
180 }
181 if (isset($this->passed_post_data[$key])) {
182 return $t->transform($this->passed_post_data[$key]);
183 }
184 if (isset($this->passed_query_params[$key])) {
185 return $t->transform($this->passed_query_params[$key]);
186 }
187 return null;
188 }
189
193 protected function getIds(): array
194 {
195 return $this->intArray("id");
196 }
197
201 protected function getTableIds(string $key): array
202 {
203 return $this->strArray($key);
204 }
205
206 protected function getTableAction(string $key): string
207 {
208 return $this->str($key);
209 }
210
214 protected function getInterruptiveItemIds(): array
215 {
216 return $this->intArray("interruptive_items");
217 }
218}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Skill gui global request wrapper.
intArray(string $key)
get integer array kindly
__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.
bool(string $key)
get bool parameter kindly
int(string $key)
get integer parameter kindly
boolArray(string $key)
get bool array kindly
strArray(string $key)
get string array kindly
str(string $key)
get string parameter kindly
isArray(string $key)
Check if parameter is an array.
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...