ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Filesystem\Util\LegacyPathHelper Class Reference

The legacy path helper provides convenient functions for the integration of the filesystem service within legacy components. More...

+ Collaboration diagram for ILIAS\Filesystem\Util\LegacyPathHelper:

Static Public Member Functions

static deriveLocationFrom (string $absolute_path)
 
static deriveFilesystemFrom (string $absolute_path)
 Tries to fetch the filesystem responsible for the absolute path. More...
 
static createRelativePath (string $absolute_path)
 Creates a relative path from an absolute path which starts with a valid storage location. More...
 

Static Private Member Functions

static resolveRelativePath (string $possible_path, string $absolute_path)
 
static checkPossiblePath (string $possible_path, string $absolute_path)
 
static listPaths ()
 

Detailed Description

The legacy path helper provides convenient functions for the integration of the filesystem service within legacy components.

This class should be deprecated with ILIAS 5.5 or earlier.

Author
Nicolas Schäfli ns@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 34 of file LegacyPathHelper.php.

Member Function Documentation

◆ checkPossiblePath()

static ILIAS\Filesystem\Util\LegacyPathHelper::checkPossiblePath ( string  $possible_path,
string  $absolute_path 
)
staticprivate

Definition at line 201 of file LegacyPathHelper.php.

201 : bool
202 {
203 $real_possible_path = realpath($possible_path);
204
205 return match (true) {
206 $possible_path === $absolute_path => true,
207 $real_possible_path === $absolute_path => true,
208 is_string($possible_path) && str_starts_with($absolute_path, $possible_path) => true,
209 is_string($real_possible_path) && str_starts_with($absolute_path, $real_possible_path) => true,
210 default => false,
211 };
212 }

Referenced by ILIAS\Filesystem\Util\LegacyPathHelper\createRelativePath(), ILIAS\Filesystem\Util\LegacyPathHelper\deriveFilesystemFrom(), and ILIAS\Filesystem\Util\LegacyPathHelper\deriveLocationFrom().

+ Here is the caller graph for this function:

◆ createRelativePath()

static ILIAS\Filesystem\Util\LegacyPathHelper::createRelativePath ( string  $absolute_path)
static

Creates a relative path from an absolute path which starts with a valid storage location.

The primary use case for this method is to trim the path after the filesystem was fetch via the deriveFilesystemFrom method.

Parameters
string$absolute_pathThe path which should be trimmed.
Returns
string The trimmed relative path.
Exceptions

InvalidArgumentException Thrown if the path does not start with a valid storage location.

See also
LegacyPathHelper::deriveFilesystemFrom()

Definition at line 131 of file LegacyPathHelper.php.

131 : string
132 {
133 [
134 $web,
135 $webRelativeWithLeadingDot,
136 $webRelativeWithoutLeadingDot,
137 $storage,
138 $customizing,
139 $customizingRelativeWithLeadingDot,
140 $libs,
141 $libsRelativeWithLeadingDot,
142 $temp,
143 $nodeModules,
144 $nodeModulesWithLeadingDot
145 ] = self::listPaths();
146
147 return match (true) {
148 self::checkPossiblePath($webRelativeWithoutLeadingDot, $absolute_path) => self::resolveRelativePath(
149 $webRelativeWithoutLeadingDot,
150 $absolute_path
151 ),
152 self::checkPossiblePath($webRelativeWithLeadingDot, $absolute_path) => self::resolveRelativePath(
153 $webRelativeWithLeadingDot,
154 $absolute_path
155 ),
156 self::checkPossiblePath($web, $absolute_path) => self::resolveRelativePath($web, $absolute_path),
157 self::checkPossiblePath($temp, $absolute_path) => self::resolveRelativePath($temp, $absolute_path),
158 self::checkPossiblePath($storage, $absolute_path) => self::resolveRelativePath($storage, $absolute_path),
159 self::checkPossiblePath($customizing, $absolute_path) => self::resolveRelativePath(
160 $customizing,
161 $absolute_path
162 ),
163 self::checkPossiblePath($customizingRelativeWithLeadingDot, $absolute_path) => self::resolveRelativePath(
164 $customizingRelativeWithLeadingDot,
165 $absolute_path
166 ),
167 self::checkPossiblePath($libs, $absolute_path), self::checkPossiblePath(
168 $libsRelativeWithLeadingDot,
169 $absolute_path
170 ) => self::resolveRelativePath($libsRelativeWithLeadingDot, $absolute_path),
171 self::checkPossiblePath($nodeModules, $absolute_path), self::checkPossiblePath(
172 $nodeModulesWithLeadingDot,
173 $absolute_path
174 ) => self::resolveRelativePath($nodeModulesWithLeadingDot, $absolute_path),
175 default => throw new \InvalidArgumentException(
176 "Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$absolute_path}'"
177 ),
178 };
179 }
static checkPossiblePath(string $possible_path, string $absolute_path)
static resolveRelativePath(string $possible_path, string $absolute_path)

References ILIAS\Filesystem\Util\LegacyPathHelper\checkPossiblePath(), ILIAS\Filesystem\Util\LegacyPathHelper\listPaths(), and ILIAS\Filesystem\Util\LegacyPathHelper\resolveRelativePath().

Referenced by LegacyPathHelperHelper\createRelativePath(), ILIAS\MediaCast\BackgroundTasks\DownloadAllZipInteraction\interaction(), ILIAS\ResourceStorage\StorageHandler\FileSystemBased\AbstractFileSystemStorageHandler\storeStream(), ILIAS\Filesystem\Util\LegacyPathHelperTest\testCreateRelativePathWithInvalidTargetWhichShouldFail(), ILIAS\Filesystem\Util\LegacyPathHelperTest\testCreateRelativePathWithStorageTargetWhichShouldSucceed(), and ILIAS\Filesystem\Util\LegacyPathHelperTest\testCreateRelativePathWithWebTargetWhichShouldSucceed().

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

◆ deriveFilesystemFrom()

static ILIAS\Filesystem\Util\LegacyPathHelper::deriveFilesystemFrom ( string  $absolute_path)
static

Tries to fetch the filesystem responsible for the absolute path.

Please note that the function is case sensitive.

Relative paths are also detected for the ILIAS web storage like './public/data/default'

Parameters
string$absolute_pathThe absolute used for the filesystem search.
Returns
Filesystem The responsible filesystem for the given path.
Exceptions

InvalidArgumentException Thrown if no filesystem is responsible for the given path.

Definition at line 84 of file LegacyPathHelper.php.

84 : Filesystem
85 {
86 [
87 $web,
88 $webRelativeWithLeadingDot,
89 $webRelativeWithoutLeadingDot,
90 $storage,
91 $customizing,
92 $customizingRelativeWithLeadingDot,
93 $libs,
94 $libsRelativeWithLeadingDot,
95 $temp,
96 $nodeModules,
97 $nodeModulesWithLeadingDot
98 ] = self::listPaths();
99
100 return match (true) {
101 self::checkPossiblePath($temp, $absolute_path) => self::filesystems()->temp(),
102 self::checkPossiblePath($web, $absolute_path) => self::filesystems()->web(),
103 self::checkPossiblePath($webRelativeWithLeadingDot, $absolute_path) => self::filesystems()->web(),
104 self::checkPossiblePath($webRelativeWithoutLeadingDot, $absolute_path) => self::filesystems()->web(),
105 self::checkPossiblePath($storage, $absolute_path) => self::filesystems()->storage(),
106 self::checkPossiblePath($customizing, $absolute_path) => self::filesystems()->customizing(),
107 self::checkPossiblePath($customizingRelativeWithLeadingDot, $absolute_path) => self::filesystems(
108 )->customizing(),
109 self::checkPossiblePath($libs, $absolute_path) => self::filesystems()->libs(),
110 self::checkPossiblePath($libsRelativeWithLeadingDot, $absolute_path) => self::filesystems()->libs(),
111 self::checkPossiblePath($nodeModules, $absolute_path) => self::filesystems()->nodeModules(),
112 self::checkPossiblePath($nodeModulesWithLeadingDot, $absolute_path) => self::filesystems()->nodeModules(),
113 default => throw new \InvalidArgumentException(
114 "Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$absolute_path}'"
115 ),
116 };
117 }
static filesystems()
Returns the loaded filesystems.

References ILIAS\Filesystem\Util\LegacyPathHelper\checkPossiblePath(), ILIAS\Filesystem\filesystems(), and ILIAS\Filesystem\Util\LegacyPathHelper\listPaths().

Referenced by ILIAS\Filesystem\Util\LegacyPathHelperTest\testDeriveFilesystemFromWithAbsoluteLibsTargetWhichShouldSucceed(), ILIAS\Filesystem\Util\LegacyPathHelperTest\testDeriveFilesystemFromWithInvalidTargetWhichShouldFail(), ILIAS\Filesystem\Util\LegacyPathHelperTest\testDeriveFilesystemFromWithRelativeLibsTargetWhichShouldSucceed(), ILIAS\Filesystem\Util\LegacyPathHelperTest\testDeriveFilesystemFromWithStorageTargetWhichShouldSucceed(), and ILIAS\Filesystem\Util\LegacyPathHelperTest\testDeriveFilesystemFromWithWebTargetWhichShouldSucceed().

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

◆ deriveLocationFrom()

static ILIAS\Filesystem\Util\LegacyPathHelper::deriveLocationFrom ( string  $absolute_path)
static

Definition at line 38 of file LegacyPathHelper.php.

38 : int
39 {
40 [
41 $web,
42 $webRelativeWithLeadingDot,
43 $webRelativeWithoutLeadingDot,
44 $storage,
45 $customizing,
46 $customizingRelativeWithLeadingDot,
47 $libs,
48 $libsRelativeWithLeadingDot,
49 $temp,
50 $nodeModules,
51 $nodeModulesWithLeadingDot
52 ] = self::listPaths();
53
54 return match (true) {
55 self::checkPossiblePath($temp, $absolute_path) => Location::TEMPORARY,
57 $webRelativeWithLeadingDot,
58 $absolute_path
59 ), self::checkPossiblePath($webRelativeWithoutLeadingDot, $absolute_path) => Location::WEB,
60 self::checkPossiblePath($storage, $absolute_path) => Location::STORAGE,
61 self::checkPossiblePath($customizing, $absolute_path), self::checkPossiblePath(
62 $customizingRelativeWithLeadingDot,
63 $absolute_path
65 default => throw new \InvalidArgumentException(
66 "Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$absolute_path}'"
67 ),
68 };
69 }
const TEMPORARY
The ILIAS temporary directory.
Definition: Location.php:53
const CUSTOMIZING
The filesystem within the web root where all the skins and plugins are saved.
Definition: Location.php:48
const WEB
The filesystem within the ilias web root.
Definition: Location.php:38
const STORAGE
The filesystem outside of the ilias web root.
Definition: Location.php:43

References ILIAS\Filesystem\Util\LegacyPathHelper\checkPossiblePath(), ILIAS\FileUpload\Location\CUSTOMIZING, ILIAS\Filesystem\Util\LegacyPathHelper\listPaths(), ILIAS\FileUpload\Location\STORAGE, ILIAS\FileUpload\Location\TEMPORARY, and ILIAS\FileUpload\Location\WEB.

Referenced by ILIAS\ResourceStorage\StorageHandler\FileSystemBased\AbstractFileSystemStorageHandler\storeStream().

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

◆ listPaths()

static ILIAS\Filesystem\Util\LegacyPathHelper::listPaths ( )
staticprivate
Returns
mixed[]

Definition at line 217 of file LegacyPathHelper.php.

217 : array
218 {
219 $web = CLIENT_WEB_DIR;
220 $webRelativeWithLeadingDot = './' . ILIAS_WEB_DIR . '/' . CLIENT_ID;
221 $webRelativeWithoutLeadingDot = ILIAS_WEB_DIR . '/' . CLIENT_ID;
222 $storage = CLIENT_DATA_DIR;
223 $customizing = ILIAS_ABSOLUTE_PATH . '/public/Customizing';
224 $customizingRelativeWithLeadingDot = './Customizing';
225 $libs = ILIAS_ABSOLUTE_PATH . '/vendor';
226 $libsRelativeWithLeadingDot = "./vendor";
227 $temp = CLIENT_DATA_DIR . "/temp";
228 $nodeModules = ILIAS_ABSOLUTE_PATH . '/node_modules';
229 $nodeModulesWithLeadingDot = './node_modules';
230
231 return [
232 $web,
233 $webRelativeWithLeadingDot,
234 $webRelativeWithoutLeadingDot,
235 $storage,
236 $customizing,
237 $customizingRelativeWithLeadingDot,
238 $libs,
239 $libsRelativeWithLeadingDot,
240 $temp,
241 $nodeModules,
242 $nodeModulesWithLeadingDot
243 ];
244 }
const CLIENT_ID
Definition: constants.php:41
const ILIAS_WEB_DIR
Definition: constants.php:45
const CLIENT_WEB_DIR
Definition: constants.php:47
const CLIENT_DATA_DIR
Definition: constants.php:46

References CLIENT_DATA_DIR, CLIENT_ID, CLIENT_WEB_DIR, and ILIAS_WEB_DIR.

Referenced by ILIAS\Filesystem\Util\LegacyPathHelper\createRelativePath(), ILIAS\Filesystem\Util\LegacyPathHelper\deriveFilesystemFrom(), and ILIAS\Filesystem\Util\LegacyPathHelper\deriveLocationFrom().

+ Here is the caller graph for this function:

◆ resolveRelativePath()

static ILIAS\Filesystem\Util\LegacyPathHelper::resolveRelativePath ( string  $possible_path,
string  $absolute_path 
)
staticprivate

Definition at line 181 of file LegacyPathHelper.php.

181 : string
182 {
183 $real_possible_path = realpath($possible_path);
184
185 return match (true) {
186 $possible_path === $absolute_path, $real_possible_path === $absolute_path => "",
187 str_starts_with($absolute_path, $possible_path) => substr(
188 $absolute_path,
189 strlen($possible_path) + 1
190 ),
191 str_starts_with($absolute_path, $real_possible_path) => substr(
192 $absolute_path,
193 strlen($real_possible_path) + 1
194 ),
195 default => throw new \InvalidArgumentException(
196 "Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$absolute_path}'"
197 ),
198 };
199 }

Referenced by ILIAS\Filesystem\Util\LegacyPathHelper\createRelativePath().

+ Here is the caller graph for this function:

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