ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWebDAVUriBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use Psr\Http\Message\RequestInterface;
22use Psr\Http\Message\UriInterface;
23
25{
29 protected array $schemas = [
30 'default' => 'http',
31 'konqueror' => 'webdav',
32 'nautilus' => 'dav'
33 ];
34
35 protected string $mount_instructions_query = 'mount-instructions';
36 protected string $webdav_script_name = 'webdav.php';
37 protected UriInterface $uri;
38 protected string $host;
39 protected string $client_id = CLIENT_ID;
40 protected string $web_path_to_script;
41
42 public function __construct(protected RequestInterface $request)
43 {
44 $this->uri = $this->request->getUri();
45 $this->host = $this->uri->getHost();
46 $this->web_path_to_script = $this->changePathToWebDavScript($this->uri->getPath());
47 }
48
49 protected function changePathToWebDavScript(string $a_original_path): string
50 {
51 $exploded_path = explode('/', $a_original_path);
52
53 if (in_array($this->webdav_script_name, $exploded_path)) {
54 return implode('/', array_splice($exploded_path, 0, -2));
55 }
56
57 return implode('/', array_splice($exploded_path, 0, -1)) . '/' . $this->webdav_script_name;
58 }
59
60 protected function getWebDavPathToRef(int $a_ref_id): string
61 {
62 return "$this->web_path_to_script/$this->client_id/ref_$a_ref_id";
63 }
64
65 protected function getWebDavPathToLanguageTemplate(string $language): string
66 {
67 return "$this->web_path_to_script/$this->client_id/$language";
68 }
69
70 protected function getWebDavUriByPlaceholderName(string $placeholder_name, int $a_ref_id): string
71 {
72 $scheme = $this->schemas[$placeholder_name];
73 if ($this->uri->getScheme() === 'https') {
74 $scheme .= 's';
75 }
76 return $scheme . '://' . $this->host . $this->getWebDavPathToRef($a_ref_id);
77 }
78
79 public function getWebDavDefaultUri(int $a_ref_id): string
80 {
81 return $this->getWebDavUriByPlaceholderName('default', $a_ref_id);
82 }
83
84 public function getWebDavNautilusUri(int $a_ref_id): string
85 {
86 return $this->getWebDavUriByPlaceholderName('nautilus', $a_ref_id);
87 }
88
89 public function getWebDavKonquerorUri(int $a_ref_id): string
90 {
91 return $this->getWebDavUriByPlaceholderName('konqueror', $a_ref_id);
92 }
93
94 public function getUriToMountInstructionModalByRef(int $a_ref_id): string
95 {
96 return $this->getWebDavPathToRef($a_ref_id) . '?' . $this->mount_instructions_query;
97 }
98
99 public function getUriToMountInstructionModalByLanguage(string $language): string
100 {
102 }
103}
__construct(protected RequestInterface $request)
getWebDavPathToLanguageTemplate(string $language)
getWebDavNautilusUri(int $a_ref_id)
getWebDavDefaultUri(int $a_ref_id)
changePathToWebDavScript(string $a_original_path)
getWebDavUriByPlaceholderName(string $placeholder_name, int $a_ref_id)
getUriToMountInstructionModalByRef(int $a_ref_id)
getWebDavKonquerorUri(int $a_ref_id)
getUriToMountInstructionModalByLanguage(string $language)
const CLIENT_ID
Definition: constants.php:41