ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Input.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28use ILIAS\GlobalScreen\GUI\Hasher;
29use Psr\Http\Message\ServerRequestInterface;
33
38class Input
39{
40 use Hasher;
41
45 public const ALL_OBJECTS = 'ALL_OBJECTS';
49 private const INTERRUPTIVE_ITEMS = 'interruptive_items';
50
51 public function __construct(
52 private Services $http,
54 private Factory $data_factory,
55 private \ilLanguage $lng,
56 private Flow $flow
57 ) {
58 }
59
60 public function getFirstFromRequest(
62 ): string {
63 if ($token === null) {
64 return '';
65 }
66
67 if ($token instanceof TokenContainer) {
68 $token = $token->token();
69 }
70
71 $query_params = $this->request()->getQueryParams(); // aka $_GET
72 $name = $token instanceof URLBuilderToken ? $token->getName() : $token;
73 $id = $query_params[$name] ?? ''; // field id
74
75 if (is_array($id) && count($id) === 1 && isset($id[0]) && $id[0] === self::ALL_OBJECTS) {
76 return self::ALL_OBJECTS; // special case for all objects
77 }
78
79 if (is_array($id)) {
80 $id = $id[0] ?? null;
81 return $id === null ? '' : $this->unhash($id);
82 }
83
84 return $this->unhash($id);
85 }
86
87 public function keepTokens(PonsGUI $gui): void
88 {
89 foreach ($gui->getTokensToKeep() as $token) {
90 $this->keep($token);
91 }
92 }
93
94 public function keep(
96 ): void {
97 if ($token instanceof TokenContainer) {
98 $token = $token->token();
99 }
100 $ctrl = $this->flow->ctrl();
101 $current_class = $ctrl->getCmdClass();
102 $name = $token instanceof URLBuilderToken ? $token->getName() : $token;
103 $ctrl->setParameterByClass($current_class, $name, $this->hash($this->getFirstFromRequest($token)));
104 }
105
106 public function getAllFromRequest(
108 ): array {
109 if ($token === null) {
110 return [];
111 }
112
113 if ($token instanceof TokenContainer) {
114 $token = $token->token();
115 }
116
117 $query_params = $this->request()->getQueryParams(); // aka $_GET
118 $name = $token instanceof URLBuilderToken ? $token->getName() : $token;
119 $ids = $query_params[$name] ?? []; // array of field ids
120 $ids = is_array($ids) ? $ids : [$ids];
121
122 // all objects
123 if (($ids[0] ?? null) === self::ALL_OBJECTS) {
124 return [self::ALL_OBJECTS]; // currently we cannot support all
125 }
126
127 // check interruptive items
128 if (($interruptive_items = $this->http->request()->getParsedBody()[self::INTERRUPTIVE_ITEMS] ?? false)) {
129 foreach ($interruptive_items as $interruptive_item) {
130 $ids[] = $interruptive_item;
131 }
132 }
133
134 return array_map(fn($id): string => $this->unhash($id), $ids);
135 }
136
137 public function buildToken(string $namespace, string $token, ?URI $uri = null): TokenContainer
138 {
139 if ($uri === null) {
140 $uri = $this->flow->getHereAsURI();
141 }
142
143 $builder = new URLBuilder($uri);
144
145 return new TokenContainer(...$builder->acquireParameter([$namespace], $token));
146 }
147
148 public function request(): ServerRequestInterface
149 {
150 return $this->http->request();
151 }
152
153}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds data types.
Definition: Factory.php:36
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
getFirstFromRequest(null|string|URLBuilderToken|TokenContainer $token)
Definition: Input.php:60
buildToken(string $namespace, string $token, ?URI $uri=null)
Definition: Input.php:137
keep(null|string|URLBuilderToken|TokenContainer $token)
Definition: Input.php:94
getAllFromRequest(null|string|URLBuilderToken|TokenContainer $token)
Definition: Input.php:106
__construct(private Services $http, private Refinery\Factory $refinery, private Factory $data_factory, private \ilLanguage $lng, private Flow $flow)
Definition: Input.php:51
Class Services.
Definition: Services.php:38
language handling
$http
Definition: deliver.php:30
if($err=$client->getError()) $namespace
static http()
Fetches the global http state from ILIAS.
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
$token
Definition: xapitoken.php:70