ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
GUIRequest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\User\Profile;
22
23use ILIAS\HTTP\Services as RequestServices;
25use ILIAS\Refinery\Factory as Refinery;
27
29{
34 private array $post;
35
36 public function __construct(
37 RequestServices $request,
38 private Refinery $refinery
39 ) {
40 $this->wrapper = $request->wrapper();
41 $this->post = $request->request()->getParsedBody();
42 }
43
44 public function getUserId(): int
45 {
46 $user_id = $this->int('user_id');
47 if ($user_id !== 0) {
48 return $this->int('user_id');
49 }
50 return $this->int('user');
51 }
52
53 public function getBackUrl(): string
54 {
55 return $this->str('back_url');
56 }
57
58 public function getBaseClass(): string
59 {
60 return $this->str('baseClass');
61 }
62
63 public function getPrompted(): int
64 {
65 return $this->int('prompted');
66 }
67
68 public function getOsdId(): int
69 {
70 return $this->int('osd_id');
71 }
72
73 public function getFieldId(): string
74 {
75 return $this->str('f');
76 }
77
78 public function getTerm(): string
79 {
80 return $this->str('term');
81 }
82
83 public function getToken(): string
84 {
85 return $this->str('token');
86 }
87
88 private function int(string $key): int
89 {
90 $source = $this->existsInPostOrQuery($key);
91 if ($source === '') {
92 return 0;
93 }
94
95 $transformation = $this->refinery->kindlyTo()->int();
96 return $this->getFromQueryOrPost($key, $transformation, $source);
97 }
98
99 private function str(string $key): string
100 {
101 $source = $this->existsInPostOrQuery($key);
102 if ($source === '') {
103 return '';
104 }
105
106 $transformation = $this->refinery->kindlyTo()->string();
107 return $this->getFromQueryOrPost($key, $transformation, $source);
108 }
109
114 public function getParsedBody(): array
115 {
116 return $this->post;
117 }
118
123 private function existsInPostOrQuery(string $key): string
124 {
125 if ($this->wrapper->post()->has($key)) {
126 return 'post';
127 }
128
129 if ($this->wrapper->query()->has($key)) {
130 return 'query';
131 }
132
133 return '';
134 }
135
136 private function getFromQueryOrPost(string $key, Transformation $transformation, string $source): string|int
137 {
138 if ($source === 'query') {
139 return $this->wrapper->query()->retrieve($key, $transformation);
140 }
141
142 return $this->wrapper->post()->retrieve($key, $transformation);
143 }
144}
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
__construct(RequestServices $request, private Refinery $refinery)
Definition: GUIRequest.php:36
getFromQueryOrPost(string $key, Transformation $transformation, string $source)
Definition: GUIRequest.php:136
A transformation is a function from one datatype to another.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...