ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
CalledContexts.php
Go to the documentation of this file.
2
4use LogicException;
5
11{
12
16 private $call_locations = [];
17
21 public function current() : ScreenContext
22 {
23 return $this->getLast();
24 }
25
29 public function push(ScreenContext $context)
30 {
31 $this->claim($context);
32 }
33
34 public function clear() : void
35 {
36 $this->call_locations = [];
37 $this->stack = [];
38 }
39
43 public function claim(ScreenContext $context)
44 {
45 $this->checkCallLocation($context);
46
47 if (in_array($context, $this->stack)) {
48 throw new LogicException("A context can only be claimed once");
49 }
50 if (end($this->stack) instanceof ScreenContext) {
51 $context = $context->withAdditionalData($this->getLast()->getAdditionalData());
52 }
53
54 parent::push($context);
55 }
56
61 {
62 $called_classes = array_filter(
63 debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS),
64 function ($item) {
65 if (!isset($item['class'])) {
66 return false;
67 }
68
69 return (!in_array($item['class'], [CalledContexts::class, ContextCollection::class]));
70 }
71 );
72 array_walk(
73 $called_classes,
74 function (&$item) {
75 $item = $item['class'] . ":" . $item['line'];
76 }
77 );
78
79 $call_location = reset($called_classes);
80
81 if (isset($this->call_locations[$context->getUniqueContextIdentifier()])) {
82 $first_location = $this->call_locations[$context->getUniqueContextIdentifier()];
83 throw new LogicException("context '{$context->getUniqueContextIdentifier()}' already claimed in $first_location, second try in $call_location");
84 }
85 $this->call_locations[$context->getUniqueContextIdentifier()] = $call_location;
86 }
87}
An exception for terminatinating execution or to throw for unit testing.
$context
Definition: webdav.php:26