ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
AbstractBaseItem.php
Go to the documentation of this file.
2
8
13abstract class AbstractBaseItem implements isItem
14{
19 protected $position = 0;
27 protected $available_callable = true;
43 protected $is_always_available = false;
52
58 {
59 $this->provider_identification = $provider_identification;
60 }
61
66 {
68 }
69
73 public function withVisibilityCallable(callable $is_visible) : isItem
74 {
75 $clone = clone($this);
76 $clone->visiblility_callable = $is_visible;
77
78 return $clone;
79 }
80
84 public function isVisible() : bool
85 {
86 if (isset($this->is_visible_static)) {
88 }
89 if (!$this->isAvailable()) {
90 return $this->is_visible_static = false;
91 }
92 if (is_callable($this->visiblility_callable)) {
94
95 $value = $callable();
96
97 return $this->is_visible_static = $value;
98 }
99
100 return $this->is_visible_static = true;
101 }
102
106 public function withAvailableCallable(callable $is_available) : isItem
107 {
108 $clone = clone($this);
109 $clone->available_callable = $is_available;
110
111 return $clone;
112 }
113
117 public function isAvailable() : bool
118 {
119 if ($this->isAlwaysAvailable() === true) {
120 return true;
121 }
122 if (is_callable($this->available_callable)) {
123 $callable = $this->available_callable;
124
125 return $callable();
126 }
127
128 return true;
129 }
130
134 public function withNonAvailableReason(Legacy $element) : isItem
135 {
136 $clone = clone $this;
137 $clone->non_available_reason = $element;
138
139 return $clone;
140 }
141
145 public function getNonAvailableReason() : Legacy
146 {
147 global $DIC;
148
149 return $this->non_available_reason instanceof Legacy ? $this->non_available_reason : $DIC->ui()->factory()->legacy("");
150 }
151
155 public function isAlwaysAvailable() : bool
156 {
158 }
159
163 public function withAlwaysAvailable(bool $always_active) : isItem
164 {
165 $clone = clone($this);
166 $clone->is_always_available = $always_active;
167
168 return $clone;
169 }
170
174 public function getPosition() : int
175 {
176 return $this->position;
177 }
178
182 public function withPosition(int $position) : isItem
183 {
184 $clone = clone($this);
185 $clone->position = $position;
186
187 return $clone;
188 }
189
193 public function setTypeInformation(TypeInformation $information) : isItem
194 {
195 $this->type_information = $information;
196
197 return $this;
198 }
199
204 {
205 return $this->type_information instanceof TypeInformation ? $this->type_information : new TypeInformation(get_class($this), get_class($this));
206 }
207
208 public function isTop() : bool
209 {
210 if ($this instanceof isChild) {
211 return $this->getParent() instanceof NullIdentification || (int) $this->getParent()->serialize() === false;
212 }
213 if ($this instanceof isTopItem && $this instanceof isInterchangeableItem) {
214 return $this->getParent() === null || $this->getParent() instanceof NullIdentification;
215 }
216 return $this instanceof isTopItem;
217 }
218}
An exception for terminatinating execution or to throw for unit testing.
setTypeInformation(TypeInformation $information)
@inheritDoc
__construct(IdentificationInterface $provider_identification)
AbstractBaseItem constructor.
$DIC
Definition: xapitoken.php:46