ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Pons.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
32use ILIAS\GlobalScreen\GUI\I18n\Translator;
38
43class Pons
44{
45 private Input $input;
46 private Translator $translator;
47 private Output $output;
48 private Flow $flow;
49 private Access $access;
50 private Tabs $tabs;
51 private ?PonsGUI $latest_gui = null;
52
53 public function __construct(
55 UIServices $ui_services,
56 private \ilCtrlInterface $ctrl,
58 Factory $data_factory,
60 RBACServices $rbac_services,
61 \ilObjUser $user,
63 \ilToolbarGUI $toolbar,
64 array $language_modules = [],
65 ?TranslationsRepository $translations_repository = null,
66 ) {
67 $this->flow = new Flow(
68 $http,
69 $ctrl,
70 );
71
72 $this->input = new Input(
73 $http,
75 $data_factory,
76 $lng,
77 $this->flow
78 );
79
80 $this->translator = new Translator(
81 $lng,
82 $translations_repository,
83 ...$language_modules
84 );
85
86 $this->tabs = new Tabs(
87 $this->translator,
88 $ctrl,
89 $tabs,
90 $this->flow
91 );
92
93 $this->output = new Output(
94 $ui_services,
95 $http,
96 $this->translator,
97 $this->tabs,
98 $toolbar
99 );
100
101 $this->access = new Access(
102 $rbac_services,
103 $http,
104 $refinery,
105 );
106 }
107
108 public function handle(string $entry_tab, array $post_handling_classes = []): bool
109 {
110 $next_class = $this->ctrl->getNextClass();
111 $tab = $this->tabs->structure()->getById($entry_tab);
112
113 if (empty($next_class)) {
114 if ($tab === null) {
115 throw new \RuntimeException('Handling Class not found');
116 }
117
118 $this->tabs->activate($entry_tab);
119
120 return false; // we delegate this further
121 }
122 if ($next_class === strtolower(MultiLanguageGUI::class)) {
123 if ($this->latest_gui !== null) {
124 $item = $this->latest_gui->getCurrentItem();
125 $back_target = $this->flow->getTargetURI(
126 $tab?->getHandlingClass() ?? ''
127 );
128 }
129
130 $back_target ??= $this->flow->getParentAsURI('');
131 $this->ctrl->forwardCommand(
133 $this,
134 $item instanceof TranslatableItem ? $item : null,
135 $back_target,
136 )
137 );
138 return true;
139 }
140
141 if (in_array(strtolower($next_class), array_map('strtolower', $post_handling_classes), true)) {
142 return false; // we delegate this further
143 }
144
145 $tab = $this->tabs->structure()->getByHandlingClass($next_class);
146
147 if ($tab === null) {
148 throw new \RuntimeException("Handling Class `$next_class` not found");
149 }
150
151 // check permissions
152 $this->access->require($tab->getPermission());
153
154 $handling_class = $tab->getHandlingClass();
155 if (is_a($handling_class, PonsGUI::class, true)) {
156 $this->latest_gui = new $handling_class($this);
157
158 // try to check access early
159 $command = $this->flow->getCommand(PonsGUI::CMD_DEFAULT);
160 if (method_exists($this->latest_gui, $command)) {
161 $method = new \ReflectionMethod($this->latest_gui, $command);
162 $attributes = $method->getAttributes(Command::class);
163 foreach ($attributes as $attribute) {
164 $instance = $attribute->newInstance();
165 $this->access->require($instance->getPermissions());
166 }
167 }
168 }
169
170 return (bool) $this->ctrl->forwardCommand($this->latest_gui);
171 }
172
173 public function in(): Input
174 {
175 return $this->input;
176 }
177
178 public function i18n(): Translator
179 {
180 return $this->translator;
181 }
182
183 public function out(): Output
184 {
185 return $this->output;
186 }
187
188 public function flow(): Flow
189 {
190 return $this->flow;
191 }
192
193 public function access(): Access
194 {
195 return $this->access;
196 }
197
198 public function tabs(): Tabs
199 {
200 return $this->tabs;
201 }
202
203 public function latestGUI(): ?PonsGUI
204 {
205 return $this->latest_gui;
206 }
207
211 public static function fromDIC(
212 array $language_modules = [],
213 ?TranslationsRepository $translations_repository = null,
214 ): self {
215 global $DIC;
216 return new self(
217 $DIC->http(),
218 $DIC->ui(),
219 $DIC->ctrl(),
220 $DIC->refinery(),
221 new Factory(),
222 $DIC->language(),
223 $DIC->rbac(),
224 $DIC->user(),
225 $DIC['ilTabs'],
226 $DIC['ilToolbar'],
227 $language_modules,
228 $translations_repository
229 );
230 }
231}
Provides fluid interface to RBAC services.
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
Builds data types.
Definition: Factory.php:36
static fromDIC(array $language_modules=[], ?TranslationsRepository $translations_repository=null,)
@description this is only for convenience, but the constructor is still public and testing is possibl...
Definition: Pons.php:211
handle(string $entry_tab, array $post_handling_classes=[])
Definition: Pons.php:108
Translator $translator
Definition: Pons.php:46
__construct(Services $http, UIServices $ui_services, private \ilCtrlInterface $ctrl, Refinery\Factory $refinery, Factory $data_factory, \ilLanguage $lng, RBACServices $rbac_services, \ilObjUser $user, \ilTabsGUI $tabs, \ilToolbarGUI $toolbar, array $language_modules=[], ?TranslationsRepository $translations_repository=null,)
Definition: Pons.php:53
Class Services.
Definition: Services.php:38
language handling
User class.
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...
$http
Definition: deliver.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26