ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AbstractBaseItem.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27use Closure;
29
33abstract class AbstractBaseItem implements
34 isItem,
36{
38
40 protected int $position = 0;
41 protected ?Closure $available_callable = null;
42 protected ?Closure $visiblility_callable = null;
43
44 public function __construct(protected IdentificationInterface $provider_identification)
45 {
46 $this->renderer = new BaseMetaBarItemRenderer();
47 }
48
50 {
51 return $this->renderer;
52 }
53
55 {
56 return $this->provider_identification;
57 }
58
59 public function withVisibilityCallable(callable $is_visible): isItem
60 {
61 $clone = clone($this);
62 $clone->visiblility_callable = $is_visible;
63
64 return $clone;
65 }
66
67 public function isVisible(): bool
68 {
69 if (!$this->isAvailable()) {
70 return false;
71 }
72 if (is_callable($this->visiblility_callable)) {
74
75 return $callable();
76 }
77
78 return true;
79 }
80
81 public function withAvailableCallable(callable $is_available): isItem
82 {
83 $clone = clone($this);
84 $clone->available_callable = $is_available;
85
86 return $clone;
87 }
88
89 public function isAvailable(): bool
90 {
91 if (is_callable($this->available_callable)) {
92 $callable = $this->available_callable;
93
94 return $callable();
95 }
96
97 return true;
98 }
99
100 public function getPosition(): int
101 {
102 return $this->position;
103 }
104
105 public function withPosition(int $position): isItem
106 {
107 $clone = clone($this);
108 $clone->position = $position;
109
110 return $clone;
111 }
112}
renderer()
__construct(protected IdentificationInterface $provider_identification)
getPosition()
Return the default position for installation, this will be overridden by the configuration later.
withVisibilityCallable(callable $is_visible)
Pass a callable which can decide whether your element is visible for the current user.
withAvailableCallable(callable $is_available)
Pass a callable which can decide whether your element is available in general, e.g.