ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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)
 
 initHandler ()
 
 performRedirect (URI $base_uri)
 

Private Member Functions

 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 36 of file HandlerService.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 41 of file HandlerService.php.

45 {
46 $this->response_factory = new Factory($context);
47 // check handlers
48 foreach ($handler_instances as $handler_instance) {
49 if (!$handler_instance instanceof Handler) {
50 throw new \InvalidArgumentException(
51 'Handler instances must implement the Handler interface'
52 );
53 }
54 }
55 }
$context
Definition: webdav.php:31

References $context.

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 159 of file HandlerService.php.

159 : string
160 {
161 if ($context->http()->wrapper()->query()->has('soap_pw')) {
162 return \ilUtil::appendUrlParameterString(
163 $full_uri,
164 'soap_pw=' . $context->http()->wrapper()->query()->retrieve(
165 'soap_pw',
166 $context->refinery()->kindlyTo()->string()
167 )
168 );
169 }
170 if ($context->http()->wrapper()->query()->has('ext_uid')) {
171 return \ilUtil::appendUrlParameterString(
172 $full_uri,
173 'ext_uid=' . $context->http()->wrapper()->query()->retrieve(
174 'ext_uid',
175 $context->refinery()->kindlyTo()->string()
176 )
177 );
178 }
179
180 return $full_uri;
181 }

References $context.

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

+ Here is the caller graph for this function:

◆ initHandler()

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

Definition at line 57 of file HandlerService.php.

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

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 78 of file HandlerService.php.

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

References $handler, $http, $response, ILIAS\StaticURL\Handler\HandlerService\appendUnknownParameters(), 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 39 of file HandlerService.php.

◆ $response_factory

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

Definition at line 38 of file HandlerService.php.


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