ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ContextRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
35{
36 private array $contexts = [];
40 private const C_MAIN = 'main';
44 private const C_DESKTOP = 'desktop';
48 private const C_REPO = 'repo';
52 private const C_ADMINISTRATION = 'administration';
56 private const C_LTI = 'lti';
57
59 protected Factory $refinery;
60
61 public function __construct()
62 {
63 global $DIC;
64 $this->wrapper = $DIC->http()->wrapper();
65 $this->refinery = $DIC->refinery();
66 }
67
68 public function main(): ScreenContext
69 {
70 return $this->get(BasicScreenContext::class, self::C_MAIN);
71 }
72
73 public function internal(): ScreenContext
74 {
75 return $this->get(BasicScreenContext::class, 'internal');
76 }
77
78 public function external(): ScreenContext
79 {
80 return $this->get(BasicScreenContext::class, 'external');
81 }
82
83 public function desktop(): ScreenContext
84 {
85 return $this->get(BasicScreenContext::class, self::C_DESKTOP);
86 }
87
88 public function repository(): ScreenContext
89 {
90 $context = $this->get(BasicScreenContext::class, self::C_REPO);
91 $ref_id = $this->wrapper->query()->has('ref_id')
92 ? $this->wrapper->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int())
93 : null;
94 if ($ref_id) {
95 return $context->withReferenceId(new ReferenceId($ref_id));
96 }
97
98 return $context;
99 }
100
101 public function administration(): ScreenContext
102 {
103 return $this->get(BasicScreenContext::class, self::C_ADMINISTRATION);
104 }
105
106 public function lti(): ScreenContext
107 {
108 return $this->get(BasicScreenContext::class, self::C_LTI);
109 }
110
111 private function get(string $class_name, string $identifier): ScreenContext
112 {
113 if (!isset($this->contexts[$identifier])) {
114 $this->contexts[$identifier] = new $class_name($identifier);
115 }
116
117 return $this->contexts[$identifier];
118 }
119}
Builds data types.
Definition: Factory.php:36
The Collection of all available Contexts in the System.
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26
$context
Definition: webdav.php:31