ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Tool.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use Closure;
32use LogicException;
33
39{
40 protected string $title;
41 protected ?Closure $terminated_callback = null;
42 protected ?Symbol $symbol = null;
43 protected ?Component $content = null;
44 protected ?Closure $content_wrapper = null;
45 protected ?Closure $close_callback = null;
46
51 public function withTitle(string $title): hasTitle
52 {
53 $clone = clone($this);
54 $clone->title = $title;
55
56 return $clone;
57 }
58
62 public function getTitle(): string
63 {
64 return $this->title;
65 }
66
71 {
72 $clone = clone($this);
73 $clone->content_wrapper = $content_wrapper;
74
75 return $clone;
76 }
77
81 public function withContent(Component $ui_component): hasContent
82 {
83 $clone = clone($this);
84 $clone->content = $ui_component;
85
86 return $clone;
87 }
88
92 public function getContent(): Component
93 {
94 if ($this->content_wrapper !== null) {
95 $wrapper = $this->content_wrapper;
96
97 return $wrapper();
98 }
99
100 return $this->content;
101 }
102
107 {
108 // bugfix mantis 25526: make aria labels mandatory
109 if (($symbol instanceof Glyph\Glyph && $symbol->getAriaLabel() === "") ||
110 ($symbol instanceof Icon\Icon && $symbol->getLabel() === "")) {
111 throw new LogicException("the symbol's aria label MUST be set to ensure accessibility");
112 }
113
114 $clone = clone($this);
115 $clone->symbol = $symbol;
116
117 return $clone;
118 }
119
123 public function getSymbol(): Symbol
124 {
125 return $this->symbol;
126 }
127
131 public function hasSymbol(): bool
132 {
133 return ($this->symbol instanceof Symbol);
134 }
135
139 public function withTerminatedCallback(Closure $callback): supportsTerminating
140 {
141 $clone = clone $this;
142 $clone->terminated_callback = $callback;
143
144 return $clone;
145 }
146
150 public function getTerminatedCallback(): ?Closure
151 {
153 }
154
158 public function hasTerminatedCallback(): bool
159 {
160 return $this->terminated_callback instanceof Closure;
161 }
162}
withTerminatedCallback(Closure $callback)
@inheritDoc
Definition: Tool.php:139
withSymbol(Symbol $symbol)
@inheritDoc
Definition: Tool.php:106
withContent(Component $ui_component)
@inheritDoc
Definition: Tool.php:81
withContentWrapper(Closure $content_wrapper)
@inheritDoc
Definition: Tool.php:70
A component is the most general form of an entity in the UI.
Definition: Component.php:28
This describes how an icon could be modified during construction of UI.
Definition: Icon.php:29
This describes a symbol.
Definition: Symbol.php:30
getLabel()
Get the label of this icon.