ILIAS  release_7 Revision v7.30-3-g800a261c036
AbstractBaseItem.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28use Closure;
29
34abstract class AbstractBaseItem implements isItem
35{
37
41 protected $position = 0;
42
47
67 protected $is_always_available = false;
76
82 {
83 $this->provider_identification = $provider_identification;
84 }
85
90 {
92 }
93
97 public function withVisibilityCallable(callable $is_visible) : isItem
98 {
99 $clone = clone($this);
100 $clone->visiblility_callable = $is_visible;
101 $clone->is_visible_static = null;
102
103 return $clone;
104 }
105
109 public function isVisible() : bool
110 {
111 if (isset($this->is_visible_static)) {
113 }
114 if (!$this->isAvailable()) {
115 return $this->is_visible_static = false;
116 }
117 if (is_callable($this->visiblility_callable)) {
118 $callable = $this->visiblility_callable;
119
120 $value = (bool) $callable();
121
122 return $this->is_visible_static = $value;
123 }
124
125 return $this->is_visible_static = true;
126 }
127
131 public function withAvailableCallable(callable $is_available) : isItem
132 {
133 $clone = clone($this);
134 $clone->available_callable = $is_available;
135
136 return $clone;
137 }
138
142 public function isAvailable() : bool
143 {
144 if ($this->isAlwaysAvailable() === true) {
145 return true;
146 }
147 if (is_callable($this->available_callable)) {
148 $callable = $this->available_callable;
149
150 return (bool) $callable();
151 }
152
153 return true;
154 }
155
159 public function withNonAvailableReason(Legacy $element) : isItem
160 {
161 $clone = clone $this;
162 $clone->non_available_reason = $element;
163
164 return $clone;
165 }
166
170 public function getNonAvailableReason() : Legacy
171 {
172 global $DIC;
173
174 return $this->non_available_reason instanceof Legacy ? $this->non_available_reason : $DIC->ui()->factory()->legacy("");
175 }
176
180 public function isAlwaysAvailable() : bool
181 {
183 }
184
188 public function withAlwaysAvailable(bool $always_active) : isItem
189 {
190 $clone = clone($this);
191 $clone->is_always_available = $always_active;
192
193 return $clone;
194 }
195
199 public function getPosition() : int
200 {
201 return $this->position;
202 }
203
207 public function withPosition(int $position) : isItem
208 {
209 $clone = clone($this);
210 $clone->position = $position;
211
212 return $clone;
213 }
214
218 public function setTypeInformation(TypeInformation $information) : isItem
219 {
220 $this->type_information = $information;
221
222 return $this;
223 }
224
229 {
231 }
232
233 public function isTop() : bool
234 {
235 if ($this instanceof isInterchangeableItem) {
236 $changed = $this->hasChanged();
237 if ($this instanceof isChild) {
238 return $changed;
239 } elseif ($this instanceof isTopItem) {
240 return !$changed;
241 }
242 }
243
244 return $this instanceof isTopItem;
245 }
246}
An exception for terminatinating execution or to throw for unit testing.
setTypeInformation(TypeInformation $information)
@inheritDoc
__construct(IdentificationInterface $provider_identification)
AbstractBaseItem constructor.
global $DIC
Definition: goto.php:24