ILIAS
release_9 Revision v9.13-25-g2c18ec4c24f
◀ ilDoc Overview
CalledContexts.php
Go to the documentation of this file.
1
<?php
2
19
declare(strict_types=1);
20
21
namespace
ILIAS\GlobalScreen\ScreenContext\Stack
;
22
23
use
ILIAS\GlobalScreen\ScreenContext\ScreenContext
;
24
use
LogicException
;
25
use
ILIAS\GlobalScreen\ScreenContext\ContextRepository
;
26
30
final
class
CalledContexts
extends
ContextCollection
31
{
32
private
array
$call_locations
= [];
33
34
public
function
current
():
ScreenContext
35
{
36
return
$this->
getLast
();
37
}
38
39
public
function
push
(
ScreenContext
$context
): void
40
{
41
$this->
claim
(
42
$context,
43
$context->
getUniqueContextIdentifier
() ===
'external'
44
);
// external can be claimed multiple times
45
}
46
47
public
function
external
():
ContextCollection
48
{
49
$this->
claim
($this->repo->external(),
true
);
50
51
return
$this
;
52
}
53
54
public
function
clear
(): void
55
{
56
$this->call_locations = [];
57
$this->stack = [];
58
}
59
60
protected
function
claim
(
ScreenContext
$context
,
bool
$silent =
false
): void
61
{
62
$this->
checkCallLocation
($context, $silent);
63
64
if
(!$silent && in_array($context, $this->stack)) {
65
throw
new
LogicException
(
"A context can only be claimed once"
);
66
}
67
parent::push($context);
68
}
69
70
private
function
checkCallLocation
(
ScreenContext
$context
,
bool
$silent =
false
): void
71
{
72
$called_classes = array_filter(
73
debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS),
74
function
($item):
bool
{
75
if
(!isset($item[
'class'
])) {
76
return
false
;
77
}
78
79
return
(!in_array($item[
'class'
], [CalledContexts::class, ContextCollection::class]));
80
}
81
);
82
array_walk(
83
$called_classes,
84
function
(& $item):
void
{
85
$item = ($item[
'class'
] ??
''
) .
":"
. ($item[
'line'
] ??
''
);
86
}
87
);
88
89
$call_location = reset($called_classes);
90
91
if
(!$silent && isset($this->call_locations[$context->
getUniqueContextIdentifier
()])) {
92
$first_location = $this->call_locations[$context->
getUniqueContextIdentifier
()];
93
throw
new
LogicException
(
"context '{$context->getUniqueContextIdentifier()}' already claimed in $first_location, second try in $call_location"
);
94
}
95
$this->call_locations[$context->
getUniqueContextIdentifier
()] = $call_location;
96
}
97
}
LogicException
ILIAS\GlobalScreen\ScreenContext\Stack\CalledContexts\$call_locations
array $call_locations
Definition:
CalledContexts.php:32
ILIAS\GlobalScreen\ScreenContext\Stack\ContextCollection\$this
function return $this
Definition:
ContextCollection.php:127
$context
$context
Definition:
webdav.php:31
ScreenContext
ILIAS\GlobalScreen\ScreenContext\Stack\CalledContexts\checkCallLocation
checkCallLocation(ScreenContext $context, bool $silent=false)
Definition:
CalledContexts.php:70
ILIAS\GlobalScreen\ScreenContext\Stack\CalledContexts\current
current()
Definition:
CalledContexts.php:34
ILIAS\GlobalScreen\ScreenContext\Stack
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition:
CalledContexts.php:21
ContextRepository
ILIAS\GlobalScreen\ScreenContext\Stack\ContextCollection\getLast
getLast()
Definition:
ContextCollection.php:58
ILIAS\GlobalScreen\ScreenContext\Stack\CalledContexts
Definition:
CalledContexts.php:30
ILIAS\GlobalScreen\ScreenContext\Stack\ContextCollection
Definition:
ContextCollection.php:30
ILIAS\GlobalScreen\ScreenContext\Stack\CalledContexts\external
external()
Definition:
CalledContexts.php:47
ILIAS\GlobalScreen\ScreenContext\Stack\CalledContexts\clear
clear()
Definition:
CalledContexts.php:54
ILIAS\GlobalScreen\ScreenContext\ScreenContext\getUniqueContextIdentifier
getUniqueContextIdentifier()
ILIAS\GlobalScreen\ScreenContext\Stack\CalledContexts\claim
claim(ScreenContext $context, bool $silent=false)
Definition:
CalledContexts.php:60
ILIAS\GlobalScreen\ScreenContext\ScreenContext
Interface ScreenContext.
Definition:
ScreenContext.php:29
ILIAS\GlobalScreen\ScreenContext\Stack\CalledContexts\push
push(ScreenContext $context)
Definition:
CalledContexts.php:39
src
GlobalScreen
ScreenContext
Stack
CalledContexts.php
Generated on Wed Sep 10 2025 14:12:06 for ILIAS by
1.8.13 (using
Doxyfile
)