ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ContextRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
35 final class ContextRepository
36 {
37  private array $contexts = [];
38  private const C_MAIN = 'main';
39  private const C_DESKTOP = 'desktop';
40  private const C_REPO = 'repo';
41  private const C_ADMINISTRATION = 'administration';
42  private const C_LTI = 'lti';
43 
45  protected Factory $refinery;
46 
47  public function __construct()
48  {
49  global $DIC;
50  $this->wrapper = $DIC->http()->wrapper();
51  $this->refinery = $DIC->refinery();
52  }
53 
54  public function main(): ScreenContext
55  {
56  return $this->get(BasicScreenContext::class, self::C_MAIN);
57  }
58 
59  public function internal(): ScreenContext
60  {
61  return $this->get(BasicScreenContext::class, 'internal');
62  }
63 
64  public function external(): ScreenContext
65  {
66  return $this->get(BasicScreenContext::class, 'external');
67  }
68 
69  public function desktop(): ScreenContext
70  {
71  return $this->get(BasicScreenContext::class, self::C_DESKTOP);
72  }
73 
74  public function repository(): ScreenContext
75  {
76  $context = $this->get(BasicScreenContext::class, self::C_REPO);
77  $ref_id = $this->wrapper->query()->has('ref_id')
78  ? $this->wrapper->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int())
79  : null;
80  if ($ref_id) {
81  $context = $context->withReferenceId(new ReferenceId($ref_id));
82  }
83 
84  return $context;
85  }
86 
87  public function administration(): ScreenContext
88  {
89  return $this->get(BasicScreenContext::class, self::C_ADMINISTRATION);
90  }
91 
92  public function lti(): ScreenContext
93  {
94  return $this->get(BasicScreenContext::class, self::C_LTI);
95  }
96 
97  private function get(string $class_name, string $identifier): ScreenContext
98  {
99  if (!isset($this->contexts[$identifier])) {
100  $this->contexts[$identifier] = new $class_name($identifier);
101  }
102 
103  return $this->contexts[$identifier];
104  }
105 }
$context
Definition: webdav.php:31
The Collection of all available Contexts in the System.
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...