ILIAS  trunk Revision v12.0_alpha-1329-g1094ddb0c33
ILIAS\StaticURL\Handler\HandlerService Class Reference
+ Collaboration diagram for ILIAS\StaticURL\Handler\HandlerService:

Public Member Functions

 __construct (private RequestBuilder $request_builder, private Context $context, private array $handler_instances, private SessionStore $session_store)
 
 initHandler ()
 
 performRedirect (URI $base_uri)
 

Private Member Functions

 buildCannotReachRedirect (URI $base_uri, Request $request)
 Builds the redirect target for a {. More...
 
 appendUnknownParameters (Context $context, string $full_uri)
 

Private Attributes

Factory $response_factory
 
array $handlers = []
 

Detailed Description

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 38 of file HandlerService.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\StaticURL\Handler\HandlerService::__construct ( private RequestBuilder  $request_builder,
private Context  $context,
private array  $handler_instances,
private SessionStore  $session_store 
)

Definition at line 43 of file HandlerService.php.

48 {
49 $this->response_factory = new Factory($context);
50 // check handlers
51 foreach ($handler_instances as $handler_instance) {
52 if (!$handler_instance instanceof Handler) {
53 throw new \InvalidArgumentException(
54 'Handler instances must implement the Handler interface'
55 );
56 }
57 }
58 }

Member Function Documentation

◆ appendUnknownParameters()

ILIAS\StaticURL\Handler\HandlerService::appendUnknownParameters ( Context  $context,
string  $full_uri 
)
private
Deprecated:
Thsi piece of code comes from the old goto.php and should be removed as soon as possible. Or this can be moved to the place where is is needed.

Definition at line 199 of file HandlerService.php.

199 : string
200 {
201 if ($context->http()->wrapper()->query()->has('soap_pw')) {
202 return \ilUtil::appendUrlParameterString(
203 $full_uri,
204 'soap_pw=' . $context->http()->wrapper()->query()->retrieve(
205 'soap_pw',
206 $context->refinery()->kindlyTo()->string()
207 )
208 );
209 }
210 if ($context->http()->wrapper()->query()->has('ext_uid')) {
211 return \ilUtil::appendUrlParameterString(
212 $full_uri,
213 'ext_uid=' . $context->http()->wrapper()->query()->retrieve(
214 'ext_uid',
215 $context->refinery()->kindlyTo()->string()
216 )
217 );
218 }
219
220 return $full_uri;
221 }

References ILIAS\StaticURL\Context\http(), and ILIAS\StaticURL\Context\refinery().

Referenced by ILIAS\StaticURL\Handler\HandlerService\performRedirect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildCannotReachRedirect()

ILIAS\StaticURL\Handler\HandlerService::buildCannotReachRedirect ( URI  $base_uri,
Request  $request 
)
private

Builds the redirect target for a {.

See also
CannotReach} response.

If the Request carries a ReferenceId, the repository tree is walked upwards until a parent the user can read is found; in that case {

See also
\ILIAS\StaticURL\Session\SessionStore} is populated with pending_goto so the parent course/group registration flow can show the reg_goto_parent_membership_info message and offer the join action. If no accessible parent is found (or the Request carries no ReferenceId), the user is redirected to their Starting Point / Dashboard.

Definition at line 166 of file HandlerService.php.

166 : string
167 {
168 $target_ref_id = $request->getReferenceId()?->toInt() ?? 0;
169 $fallback_ref_id = $target_ref_id > 0
170 ? $this->context->findFirstAccessibleParentRefId($target_ref_id)
171 : null;
172
173 if ($fallback_ref_id !== null) {
174 $this->session_store->set(
175 'pending_goto',
176 'goto.php?target=' . $request->getNamespace() . '_' . $target_ref_id
177 );
178 $this->context->mainTemplate()->setOnScreenMessage(
179 'info',
180 $this->context->lng()->txt('reg_goto_parent_membership_info'),
181 true
182 );
183 return $base_uri . '/ilias.php?baseClass=ilRepositoryGUI&ref_id=' . $fallback_ref_id;
184 }
185
186 $this->context->mainTemplate()->setOnScreenMessage(
187 'failure',
188 $this->context->lng()->txt('permission_denied'),
189 true
190 );
191
192 return $base_uri . '/' . ltrim(\ilUserUtil::getStartingPointAsUrl(), '/');
193 }
static getStartingPointAsUrl()

References ILIAS\StaticURL\Request\Request\getNamespace(), ILIAS\StaticURL\Request\Request\getReferenceId(), and ilUserUtil\getStartingPointAsUrl().

Referenced by ILIAS\StaticURL\Handler\HandlerService\performRedirect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initHandler()

ILIAS\StaticURL\Handler\HandlerService::initHandler ( )

Definition at line 60 of file HandlerService.php.

60 : void
61 {
62 foreach ($this->handler_instances as $handler) {
63 if (isset($this->handlers[$handler->getNamespace()])) {
64 throw new \LogicException("Namespace-Collision detected: " . $handler->getNamespace());
65 }
66 $this->handlers[$handler->getNamespace()] = $handler;
67 if ($handler instanceof AliasedHandler) {
68 foreach ($handler->getNamespaceAliasses() as $namespace_aliass) {
69 if (isset($this->handlers[$namespace_aliass])) {
70 throw new \LogicException("Namespace-Collision detected: " . $namespace_aliass);
71 }
72 $this->handlers[$namespace_aliass] = $handler;
73 }
74 }
75 }
76 }
$handler
Definition: oai.php:31

References $handler.

Referenced by ILIAS\StaticURL\Handler\HandlerService\performRedirect().

+ Here is the caller graph for this function:

◆ performRedirect()

ILIAS\StaticURL\Handler\HandlerService::performRedirect ( URI  $base_uri)
Returns
never

Definition at line 81 of file HandlerService.php.

81 : void
82 {
83 if (empty($this->handlers)) {
84 $this->initHandler();
85 }
86
87 $http = $this->context->http();
88
89 $request = $this->request_builder->buildRequest(
90 $http,
91 $this->context->refinery(),
92 $this->handlers
93 );
94 if (!$request instanceof Request) {
95 throw new \RuntimeException('No request could be built');
96 }
97
98 $handler = $this->handlers[$request->getNamespace()] ?? null;
99 if (!$handler instanceof Handler) {
100 throw new \InvalidArgumentException('No handler found for namespace ' . $request->getNamespace());
101 }
102 $response = $handler->handle($request, $this->context, $this->response_factory);
103
104 if ($response instanceof CannotHandle) {
105 $http->saveResponse(
106 $http->response()->withStatus(404),
107 );
108 $http->sendResponse();
109 $http->close();
110 }
111
112 $uri_builder = new StandardURIBuilder(new StaticURLConfig());
113
114 switch (true) {
115 case $response instanceof MaybeCanHandlerAfterLogin:
116 $target = $uri_builder->buildTarget(
117 $request->getNamespace(),
118 $request->getReferenceId(),
119 $request->getAdditionalParameters()
120 );
121 $full_uri = $base_uri . "/login.php?target=";
122 $full_uri .= str_replace('/', '_', rtrim($target, '/')); // TODO: ILIAS currently need this like this
123 if (!$this->context->isUserLoggedIn()) {
124 $full_uri .= '&cmd=force_login&lang=' . $this->context->getUserLanguage();
125 }
126 $full_uri = $this->appendUnknownParameters($this->context, $full_uri); // Read the comment below
127 break;
128 case $response instanceof CannotReach:
129 $full_uri = $this->buildCannotReachRedirect($base_uri, $request);
130 break;
131 default:
132 // Perform Redirect
133 $uri_path = $response->getURIPath() ?? '';
134 $base_path = $base_uri->getPath() ?? '';
135 if ($base_path !== '' && $base_path !== '/') {
136 $uri_path = str_replace(rtrim($base_path, '/') . '/', '', $uri_path);
137 }
138
139 for ($x = 0; $x < $response->shift(); $x++) {
140 $base_uri = $base_uri->withPath(dirname((string) $base_uri->getPath()));
141 }
142
143 $full_uri = $base_uri . '/' . trim((string) $uri_path, '/');
144 break;
145 }
146
147 $http->saveResponse(
148 $http->response()->withAddedHeader('Location', $full_uri)
149 );
150 $http->sendResponse();
151 $http->close();
152 }
withPath(?string $path=null)
Get URI with modified path.
Definition: URI.php:283
appendUnknownParameters(Context $context, string $full_uri)
buildCannotReachRedirect(URI $base_uri, Request $request)
Builds the redirect target for a {.
$http
Definition: deliver.php:30
$response
Definition: xapitoken.php:90

References $handler, $http, $response, ILIAS\StaticURL\Handler\HandlerService\appendUnknownParameters(), ILIAS\StaticURL\Handler\HandlerService\buildCannotReachRedirect(), ILIAS\Data\URI\getPath(), ILIAS\StaticURL\Handler\HandlerService\initHandler(), and ILIAS\Data\URI\withPath().

+ Here is the call graph for this function:

Field Documentation

◆ $handlers

array ILIAS\StaticURL\Handler\HandlerService::$handlers = []
private

Definition at line 41 of file HandlerService.php.

◆ $response_factory

Factory ILIAS\StaticURL\Handler\HandlerService::$response_factory
private

Definition at line 40 of file HandlerService.php.


The documentation for this class was generated from the following file: