ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCtrlContext.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Refinery\Factory as Refinery;
23
32{
37
42
46 protected Refinery $refinery;
47
52
56 protected bool $is_async = false;
57
61 protected string $target_script = 'ilias.php';
62
66 protected ?string $cmd_mode = null;
67
71 protected ?string $redirect = null;
72
76 protected ?string $base_class = null;
77
81 protected ?string $cmd_class = null;
82
86 protected ?string $cmd = null;
87
91 protected ?string $obj_type = null;
92
96 protected ?int $obj_id = null;
97
106 {
107 $this->path_factory = $path_factory;
108 $this->path = $path_factory->null();
109 $this->request_wrapper = $request_wrapper;
110 $this->refinery = $refinery;
111
112 $this->adoptRequestParameters();
113 }
114
118 public function isAsync(): bool
119 {
120 return $this->is_async;
121 }
122
126 public function getRedirectSource(): ?string
127 {
128 return $this->redirect;
129 }
130
134 public function getPath(): ilCtrlPathInterface
135 {
136 return $this->path;
137 }
138
142 public function setCmdMode(string $mode): ilCtrlContextInterface
143 {
144 $this->cmd_mode = $mode;
145 return $this;
146 }
147
151 public function getCmdMode(): ?string
152 {
153 return $this->cmd_mode;
154 }
155
160 {
161 $path = $this->path_factory->find($this, $base_class);
162
163 // only set baseclass if it's a valid target.
164 if (null !== $path->getCidPath()) {
165 $this->base_class = $base_class;
166 // only update the path if the current one is null.
167 if (null === $this->path->getCidPath()) {
168 $this->path = $path;
169 }
170 }
171
172 return $this;
173 }
174
178 public function getBaseClass(): ?string
179 {
180 return $this->base_class;
181 }
182
187 {
188 $this->target_script = $target_script;
189 return $this;
190 }
191
195 public function getTargetScript(): string
196 {
198 }
199
204 {
205 $path = $this->path_factory->find($this, $cmd_class);
206
207 // only set command class if it's a valid target.
208 if (null !== $path->getCidPath()) {
209 $this->cmd_class = $cmd_class;
210 $this->path = $path;
211 }
212
213 return $this;
214 }
215
219 public function getCmdClass(): ?string
220 {
221 // if no cmd_class is set yet, the baseclass
222 // value can be returned.
223 return $this->cmd_class ?? $this->base_class;
224 }
225
229 public function setCmd(?string $cmd): ilCtrlContextInterface
230 {
231 $this->cmd = $cmd;
232
233 return $this;
234 }
235
239 public function getCmd(): ?string
240 {
241 return $this->cmd;
242 }
243
248 {
249 $this->obj_type = $obj_type;
250 return $this;
251 }
252
256 public function getObjType(): ?string
257 {
258 return $this->obj_type;
259 }
260
265 {
266 $this->obj_id = $obj_id;
267 return $this;
268 }
269
273 public function getObjId(): ?int
274 {
275 return $this->obj_id;
276 }
277
286 protected function adoptRequestParameters(): void
287 {
288 $this->redirect = $this->getQueryParam(ilCtrlInterface::PARAM_REDIRECT);
289 $this->cmd_mode = $this->getQueryParam(ilCtrlInterface::PARAM_CMD_MODE);
290 $this->cmd = $this->getQueryParam(ilCtrlInterface::PARAM_CMD);
291
292 // the context is considered asynchronous if
293 // the command mode is 'async'.
294 if (ilCtrlInterface::CMD_MODE_ASYNC === $this->cmd_mode) {
295 $this->is_async = true;
296 }
297
298 // if an existing path is provided use it by default.
299 $existing_path = $this->getQueryParam(ilCtrlInterface::PARAM_CID_PATH);
300 if (null !== $existing_path) {
301 $this->path = $this->path_factory->existing($existing_path);
302 }
303
304 // set the provided baseclass, which might override the
305 // previously set existing path.
307 if (null !== $base_class) {
308 $this->setBaseClass($base_class);
309 }
310
311 // set or append the provided command class, which might
312 // override the previously set path again.
314 if (null !== $cmd_class) {
315 $this->setCmdClass($cmd_class);
316 }
317 }
318
325 protected function getQueryParam(string $parameter_name): ?string
326 {
327 if ($this->request_wrapper->has($parameter_name)) {
328 return $this->request_wrapper->retrieve(
329 $parameter_name,
330 $this->refinery->to()->string()
331 );
332 }
333
334 return null;
335 }
336}
Builds data types.
Definition: Factory.php:36
Class ilCtrlContext is responsible for holding the current context information.
setCmdClass(?string $cmd_class)
@inheritDoc
getQueryParam(string $parameter_name)
Helper function to retrieve request parameter values by name.
getObjId()
@inheritDoc
RequestWrapper $request_wrapper
setObjId(int $obj_id)
@inheritDoc
setTargetScript(string $target_script)
@inheritDoc
getPath()
@inheritDoc
getBaseClass()
@inheritDoc
isAsync()
@inheritDoc
setBaseClass(string $base_class)
@inheritDoc
getCmdMode()
@inheritDoc
__construct(ilCtrlPathFactory $path_factory, RequestWrapper $request_wrapper, Refinery $refinery)
ilCtrlContext Constructor
setObjType(string $obj_type)
@inheritDoc
getObjType()
@inheritDoc
ilCtrlPathInterface $path
getTargetScript()
@inheritDoc
getRedirectSource()
@inheritDoc
setCmdMode(string $mode)
@inheritDoc
adoptRequestParameters()
Adopts context properties from the according ones delivered by the current request.
ilCtrlPathFactory $path_factory
setCmd(?string $cmd)
@inheritDoc
getCmdClass()
@inheritDoc
Class ilCtrlPathFactory.
Interface RequestWrapper.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getCidPath()
Returns the CID path for the target class of the current instance.