ILIAS  release_8 Revision v8.24
class.SkillGUIRequest.php
Go to the documentation of this file.
1<?php
2
20namespace ILIAS\Skill\Service;
21
22use ILIAS\HTTP;
24
32{
34 protected Refinery\Factory $refinery;
35 protected ?array $passed_query_params = null;
36 protected ?array $passed_post_data = null;
37
42 public function __construct(
43 HTTP\Services $http,
44 Refinery\Factory $refinery,
45 ?array $passed_query_params = null,
46 ?array $passed_post_data = null
47 ) {
48 $this->http = $http;
49 $this->refinery = $refinery;
50 $this->passed_query_params = $passed_query_params;
51 $this->passed_post_data = $passed_post_data;
52 }
53
57 protected function int(string $key): int
58 {
59 $t = $this->refinery->kindlyTo()->int();
60 return (int) ($this->get($key, $t) ?? 0);
61 }
62
67 protected function intArray(string $key): array
68 {
69 if (!$this->isArray($key)) {
70 return [];
71 }
72 $t = $this->refinery->custom()->transformation(
73 static function (array $arr): array {
74 // keep keys(!), transform all values to int
75 return array_map('intval', $arr);
76 }
77 );
78 return (array) ($this->get($key, $t) ?? []);
79 }
80
84 protected function str(string $key): string
85 {
86 $t = $this->refinery->kindlyTo()->string();
87 return \ilUtil::stripSlashes((string) ($this->get($key, $t) ?? ""));
88 }
89
94 protected function strArray(string $key): array
95 {
96 if (!$this->isArray($key)) {
97 return [];
98 }
99 $t = $this->refinery->custom()->transformation(
100 static function (array $arr): array {
101 // keep keys(!), transform all values to string
102 return array_map(
103 static function ($v): string {
104 return \ilUtil::stripSlashes((string) $v);
105 },
106 $arr
107 );
108 }
109 );
110 return (array) ($this->get($key, $t) ?? []);
111 }
112
116 protected function bool(string $key): bool
117 {
118 $t = $this->refinery->kindlyTo()->bool();
119 return (bool) ($this->get($key, $t) ?? false);
120 }
121
126 protected function boolArray(string $key): array
127 {
128 if (!$this->isArray($key)) {
129 return [];
130 }
131 $t = $this->refinery->custom()->transformation(
132 static function (array $arr): array {
133 // keep keys(!), transform all values to bool
134 return array_map('boolval', $arr);
135 }
136 );
137 return (array) ($this->get($key, $t) ?? []);
138 }
139
143 protected function isArray(string $key): bool
144 {
145 if ($this->passed_query_params === null && $this->passed_post_data === null) {
146 $no_transform = $this->refinery->identity();
147 $w = $this->http->wrapper();
148 if ($w->post()->has($key)) {
149 return is_array($w->post()->retrieve($key, $no_transform));
150 }
151 if ($w->query()->has($key)) {
152 return is_array($w->query()->retrieve($key, $no_transform));
153 }
154 }
155 if (isset($this->passed_post_data[$key])) {
156 return is_array($this->passed_post_data[$key]);
157 }
158 if (isset($this->passed_query_params[$key])) {
159 return is_array($this->passed_query_params[$key]);
160 }
161 return false;
162 }
163
169 protected function get(string $key, Refinery\Transformation $t)
170 {
171 if ($this->passed_query_params === null && $this->passed_post_data === null) {
172 $w = $this->http->wrapper();
173 if ($w->post()->has($key)) {
174 return $w->post()->retrieve($key, $t);
175 }
176 if ($w->query()->has($key)) {
177 return $w->query()->retrieve($key, $t);
178 }
179 }
180 if (isset($this->passed_post_data[$key])) {
181 return $t->transform($this->passed_post_data[$key]);
182 }
183 if (isset($this->passed_query_params[$key])) {
184 return $t->transform($this->passed_query_params[$key]);
185 }
186 return null;
187 }
188
192 protected function getIds(): array
193 {
194 return $this->intArray("id");
195 }
196}
Builds data types.
Definition: Factory.php:21
Class Services.
Definition: Services.php:38
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.
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $key
Consumer key/client ID value.
Definition: System.php:193
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...