ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjectRequestRetriever.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
31{
33 protected Factory $refinery;
34
36 {
37 $this->wrapper = $wrapper;
38 $this->refinery = $refinery;
39 }
40
44 private function getFromRequest(string $key, Transformation $t)
45 {
46 if ($this->wrapper->query()->has($key)) {
47 return $this->wrapper->query()->retrieve($key, $t);
48 }
49 if ($this->wrapper->post()->has($key)) {
50 return $this->wrapper->post()->retrieve($key, $t);
51 }
52 return null;
53 }
54
55 public function has(string $key): bool
56 {
57 return $this->wrapper->query()->has($key)
58 || $this->wrapper->post()->has($key);
59 }
60
61 public function getMaybeInt(string $key, ?int $fallback = null): ?int
62 {
63 return $this->getFromRequest($key, $this->refinery->kindlyTo()->int()) ?? $fallback;
64 }
65
66 public function getMaybeString(string $key, ?string $fallback = null): ?string
67 {
68 return $this->getFromRequest($key, $this->refinery->kindlyTo()->string()) ?? $fallback;
69 }
70
71 public function getArrayOfInt(string $key): array
72 {
73 return $this->getFromRequest(
74 $key,
75 $this->refinery->kindlyTo()->dictOf(
76 $this->refinery->kindlyTo()->int()
77 )
78 ) ?? [];
79 }
80
81 public function getBool(string $key): bool
82 {
83 return $this->getFromRequest($key, $this->refinery->kindlyTo()->bool()) ?? false;
84 }
85
86 public function getSelectedIdsFromObjectList(): array
87 {
88 if ($this->wrapper->query()->has('tl_id')) {
89 return [$this->wrapper->query()->retrieve(
90 'tl_id',
91 $this->refinery->kindlyTo()->int()
92 )];
93 }
94 if ($this->wrapper->post()->has('id')) {
95 return $this->wrapper->post()->retrieve(
96 'id',
97 $this->refinery->container()->mapValues(
98 $this->refinery->kindlyTo()->int()
99 )
100 );
101 }
102
103 return [];
104 }
105}
Builds data types.
Definition: Factory.php:36
Base class for all sub item list gui's.
getMaybeInt(string $key, ?int $fallback=null)
getFromRequest(string $key, Transformation $t)
__construct(WrapperFactory $wrapper, Factory $refinery)
getMaybeString(string $key, ?string $fallback=null)
A transformation is a function from one datatype to another.