ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
StandardURIBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
32{
33 private ?URI $cache = null;
34
35 public function __construct(
36 private Configuration $config,
37 ) {
38 }
39
40 public const string SHORT = '/go/';
41 public const string LONG = '/goto.php/';
42
43 public function buildLegacy(
44 ?int $a_ref_id,
45 string $a_type = '',
46 array $a_params = [],
47 string $append = ""
48 ): string {
49 global $DIC; // we do not inject this since it's e depreacted method
50
51 $ilObjDataCache = $DIC["ilObjDataCache"];
52
53 if ($a_type === '' && $a_ref_id) {
54 $a_type = $ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($a_ref_id));
55 }
56
57 $a_params = array_merge($a_params, [$append]);
58 $a_params = array_filter($a_params, static fn($value): bool => $value !== "");
59
60 if (!empty($a_type)) {
61 return (string) $this->build(
62 $a_type,
63 $a_ref_id !== null ? new ReferenceId($a_ref_id) : null,
64 $a_params
65 );
66 }
67
68 return '';
69 }
70
71 public function build(
72 string $namespace,
73 ?ReferenceId $reference_id = null,
74 array $additional_parameters = []
75 ): URI {
76 $uri = $this->getBaseURI()
77 . $this->config->get(Config::STATIC_LINK_ENDPOINT)
78 . $this->buildTarget($namespace, $reference_id, $additional_parameters);
79
80 return new URI($uri);
81 }
82
83 public function buildTarget(
84 string $namespace,
85 ?ReferenceId $reference_id = null,
86 array $additional_parameters = []
87 ): string {
89 . ($reference_id !== null ? '/' . $reference_id->toInt() : '')
90 . '/'
91 . implode('/', $additional_parameters);
92 }
93
94 public function getBaseURI(): URI
95 {
96 if ($this->cache !== null) {
97 return $this->cache;
98 }
99
100 $base_path = $this->config->get(Config::BASE_URL);
101
102 $offset = match (true) {
103 str_contains((string) $base_path, self::SHORT) => strpos((string) $base_path, self::SHORT),
104 str_contains((string) $base_path, self::LONG) => strpos((string) $base_path, rtrim(self::LONG, '/')),
105 str_contains((string) $base_path, rtrim(self::LONG, '/')) => strpos((string) $base_path, rtrim(self::LONG, '/')),
106 str_contains((string) $base_path, 'Customizing') => strpos((string) $base_path, 'Customizing'),
107 str_contains((string) $base_path, 'src') => strpos((string) $base_path, 'src'),
108 str_contains((string) $base_path, 'webservices') => strpos((string) $base_path, 'webservices'),
109 default => false,
110 };
111
112 if ($offset === false) {
113 return $this->cache = new URI(trim((string) $base_path, '/'));
114 }
115
116 $uri_string = substr(
117 (string) $base_path,
118 0,
119 $offset
120 );
121 return $this->cache = new URI(
122 trim($uri_string, '/')
123 );
124 }
125
126}
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
buildTarget(string $namespace, ?ReferenceId $reference_id=null, array $additional_parameters=[])
build(string $namespace, ?ReferenceId $reference_id=null, array $additional_parameters=[])
buildLegacy(?int $a_ref_id, string $a_type='', array $a_params=[], string $append="")
__construct(private Configuration $config,)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($err=$client->getError()) $namespace
A configuration for the setup.
Definition: Config.php:27
get(string $class_name)
global $DIC
Definition: shib_login.php:26