ILIAS
release_6 Revision v6.24-5-g0c8bfefb3b8
◀ ilDoc Overview
SymbolDecoratorTrait.php
Go to the documentation of this file.
1
<?php declare(strict_types=1);
2
3
namespace
ILIAS\GlobalScreen\Scope\MainMenu\Factory
;
4
5
use
Closure
;
6
use
ILIAS\UI\Component\Component
;
7
use
ILIAS\UI\Component\Symbol\Symbol
;
8
use
LogicException
;
9
use
ReflectionFunction
;
10
use
ReflectionType
;
11
17
trait
SymbolDecoratorTrait
18
{
19
23
private
$symbol_decorator;
24
29
public
function
addSymbolDecorator
(
Closure
$symbol_decorator) :
hasSymbol
30
{
31
if
(!$this->
checkClosure
($symbol_decorator)) {
32
throw
new
LogicException
(
'first argument of closure must be type-hinted to \ILIAS\UI\Component\Symbol\Symbol'
);
33
}
34
if
($this->symbol_decorator instanceof
Closure
) {
35
$existing = $this->symbol_decorator;
36
$this->symbol_decorator =
static
function
(
Symbol
$c
) use ($symbol_decorator, $existing) :
Symbol
{
37
$component = $existing(
$c
);
38
39
return
$symbol_decorator($component);
40
};
41
}
else
{
42
$this->symbol_decorator = $symbol_decorator;
43
}
44
45
return
$this;
46
}
47
51
public
function
getSymbolDecorator
() : ?
Closure
52
{
53
return
$this->symbol_decorator;
54
}
55
56
private
function
checkClosure
(
Closure
$c
) : bool
57
{
58
try
{
59
$r =
new
ReflectionFunction
($c);
60
if
(count($r->getParameters()) !== 1) {
61
return
false
;
62
}
63
$first_param_type = $r->getParameters()[0]->getType();
64
if
($first_param_type instanceof
ReflectionType
&& $first_param_type->getName() !== Symbol::class) {
65
return
false
;
66
}
67
$return_type = $r->getReturnType();
68
if
($return_type === null) {
69
return
false
;
70
}
71
if
($return_type->getName() !== Symbol::class) {
72
return
false
;
73
}
74
75
return
true
;
76
}
catch
(\Throwable
$i
) {
77
return
false
;
78
}
79
}
80
}
ILIAS\GlobalScreen\Scope\MainMenu\Factory\addSymbolDecorator
addSymbolDecorator(Closure $symbol_decorator)
Definition:
SymbolDecoratorTrait.php:29
SymbolDecoratorTrait
LogicException
ILIAS\UI\Component\Symbol\Symbol
This describes a symbol.
Definition:
Symbol.php:11
Component
Closure
Symbol
ReflectionType
ILIAS\GlobalScreen\Scope\MainMenu\Factory\hasSymbol
Interface hasSymbol Methods for Entries with Symbols.
Definition:
hasSymbol.php:11
ILIAS\GlobalScreen\Scope\MainMenu\Factory\checkClosure
checkClosure(Closure $c)
Definition:
SymbolDecoratorTrait.php:56
Vendor\Package\$c
$c
Definition:
example_cleaned.php:31
ILIAS\GlobalScreen\Scope\MainMenu\Factory
Definition:
AbstractBaseItem.php:1
ILIAS\GlobalScreen\Scope\MainMenu\Factory\getSymbolDecorator
getSymbolDecorator()
Definition:
SymbolDecoratorTrait.php:51
ReflectionFunction
$i
$i
Definition:
metadata.php:24
src
GlobalScreen
Scope
MainMenu
Factory
SymbolDecoratorTrait.php
Generated on Tue Sep 2 2025 20:01:28 for ILIAS by
1.8.13 (using
Doxyfile
)