ILIAS  release_7 Revision v7.30-3-g800a261c036
ContextCollection.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
21
24
30{
34 protected $repo;
38 protected $stack = [];
39
44 public function __construct(ContextRepository $context_repository)
45 {
46 $this->repo = $context_repository;
47 }
48
52 public function push(ScreenContext $context) : void
53 {
54 $this->stack[] = $context;
55 }
56
60 public function getLast() : ?ScreenContext
61 {
62 $last = end($this->stack);
63 if ($last) {
64 return $last;
65 }
66 return null;
67 }
68
72 public function getStack() : array
73 {
74 return $this->stack;
75 }
76
80 public function getStackAsArray() : array
81 {
82 $return = [];
83 foreach ($this->stack as $item) {
84 $return[] = $item->getUniqueContextIdentifier();
85 }
86
87 return $return;
88 }
89
94 public function hasMatch(ContextCollection $other_collection) : bool
95 {
96 $mapper = function (ScreenContext $c) : string {
97 return $c->getUniqueContextIdentifier();
98 };
99 $mine = array_map($mapper, $this->getStack());
100 $theirs = array_map($mapper, $other_collection->getStack());
101
102 return (count(array_intersect($mine, $theirs)) > 0);
103 }
104
105 public function main() : self
106 {
107 $context = $this->repo->main();
108 $this->push($context);
109
110 return $this;
111 }
112
113 public function desktop() : self
114 {
115 $this->push($this->repo->desktop());
116
117 return $this;
118 }
119
120 public function repository() : self
121 {
122 $this->push($this->repo->repository());
123
124 return $this;
125 }
126
127 public function administration() : self
128 {
129 $this->push($this->repo->administration());
130
131 return $this;
132 }
133
134 public function internal() : self
135 {
136 $this->push($this->repo->internal());
137
138 return $this;
139 }
140
141 public function external() : self
142 {
143 $this->push($this->repo->external());
144
145 return $this;
146 }
147
148 public function lti() : self
149 {
150 $this->push($this->repo->lti());
151 return $this;
152 }
153}
An exception for terminatinating execution or to throw for unit testing.
__construct(ContextRepository $context_repository)
ContextCollection constructor.
$c
Definition: cli.php:37
$context
Definition: webdav.php:26