ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
AbstractBaseItem.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use Closure;
27
31abstract class AbstractBaseItem implements
32 isItem
33{
35 protected int $position = 0;
36 protected ?Closure $available_callable = null;
37 protected ?Closure $visiblility_callable = null;
38
39 public function __construct(protected IdentificationInterface $provider_identification)
40 {
41 $this->renderer = new BaseMetaBarItemRenderer();
42 }
43
45 {
46 return $this->renderer;
47 }
48
50 {
51 return $this->provider_identification;
52 }
53
54 public function withVisibilityCallable(callable $is_visible): isItem
55 {
56 $clone = clone($this);
57 $clone->visiblility_callable = $is_visible;
58
59 return $clone;
60 }
61
62 public function isVisible(): bool
63 {
64 if (!$this->isAvailable()) {
65 return false;
66 }
67 if (is_callable($this->visiblility_callable)) {
69
70 return $callable();
71 }
72
73 return true;
74 }
75
76 public function withAvailableCallable(callable $is_available): isItem
77 {
78 $clone = clone($this);
79 $clone->available_callable = $is_available;
80
81 return $clone;
82 }
83
84 public function isAvailable(): bool
85 {
86 if (is_callable($this->available_callable)) {
87 $callable = $this->available_callable;
88
89 return $callable();
90 }
91
92 return true;
93 }
94
95 public function getPosition(): int
96 {
97 return $this->position;
98 }
99
100 public function withPosition(int $position): isItem
101 {
102 $clone = clone($this);
103 $clone->position = $position;
104
105 return $clone;
106 }
107}
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.