ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
RequestTranslation.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\WebDAV\Request;
22
23use Psr\Http\Message\ServerRequestInterface;
26
31{
32 private string $endpoint;
34
35 public function __construct(
36 private Config $config,
37 private ServerRequestInterface $request
38 ) {
39 $this->endpoint = '/' . trim($this->config->getEndpoint() . '/', '/');
40 }
41
42 public function getRequestedPath(): string
43 {
44 $path = $this->request->getUri()->getPath();
45
46 $requested_path = ltrim(substr($path, strpos($path, $this->endpoint) + strlen($this->endpoint)), '/');
47
48 // Legacy client-name segment is optional: support both
49 // /webdav.php/<client_id>/ref_X and /webdav.php/ref_X
50 $client_id = $this->config->getClientId();
51 if ($client_id !== '') {
52 $segments = explode('/', $requested_path, 2);
53 if (($segments[0] ?? '') === $client_id) {
54 return $segments[1] ?? '';
55 }
56 }
57
58 return $requested_path;
59 }
60
61 public function getBasePath(): string
62 {
63 $path = $this->request->getUri()->getPath();
64 $end = strpos($path, $this->endpoint);
65 if ($end === false) {
66 return rtrim($this->endpoint, '/') . '/';
67 }
68 $base = substr($path, 0, $end) . $this->endpoint . '/';
69
70 $client_id = $this->config->getClientId();
71 if ($client_id === '') {
72 return $base;
73 }
74
75 $remainder = ltrim(substr($path, $end + strlen($this->endpoint)), '/');
76 $first_segment = explode('/', $remainder, 2)[0] ?? '';
77 if ($first_segment === $client_id) {
78 return $base . $client_id . '/';
79 }
80
81 return $base;
82 }
83
84 public function getRequestedPathAsArray(): array
85 {
86 $path = $this->getRequestedPath();
87 return explode('/', $path);
88 }
89
90 public function showMountPoint(): bool
91 {
92 return array_key_exists($this->config->getMountInstructionsQuery(), $this->request->getQueryParams());
93 }
94
95 public function setup(): void
96 {
97 $this->post = $_POST;
98 $_POST = (array) $this->post;
99 $HTTP_POST_VARS = $_POST;
100 }
101
102 public function close(): void
103 {
105 }
106}
Class SuperGlobalDropInReplacement This Class wraps SuperGlobals such as $_GET and $_POST to prevent ...
__construct(private Config $config, private ServerRequestInterface $request)
SuperGlobalDropInReplacement array $post
string $client_id
Definition: class.ilias.php:36
$_POST['cmd']
Definition: lti.php:27
$path
Definition: ltiservices.php:30