ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  }

◆ 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

Definition at line 131 of file LegacyPathHelper.php.

Referenced by ILIAS\Object\Properties\CoreProperties\TileImage\ilObjectTileImage\createFromImportDir(), LegacyPathHelperHelper\createRelativePath(), ILIAS\Repository\IRSS\IRSSWrapper\importFilesFromDirectoryToCollection(), ILIAS\Repository\IRSS\IRSSWrapper\importLocalFile(), ILIAS\ResourceStorage\StorageHandler\FileSystemBased\AbstractFileSystemStorageHandler\storeStream(), ILIAS\Filesystem\Util\LegacyPathHelperTest\testCreateRelativePathWithInvalidTargetWhichShouldFail(), ILIAS\Filesystem\Util\LegacyPathHelperTest\testCreateRelativePathWithStorageTargetWhichShouldSucceed(), and ILIAS\Filesystem\Util\LegacyPathHelperTest\testCreateRelativePathWithWebTargetWhichShouldSucceed().

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  }
+ 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

Definition at line 84 of file LegacyPathHelper.php.

References ILIAS\Filesystem\filesystems().

Referenced by ILIAS\Object\Properties\CoreProperties\TileImage\ilObjectTileImage\createFromImportDir(), ILIAS\Repository\IRSS\IRSSWrapper\importFilesFromDirectoryToCollection(), ILIAS\Repository\IRSS\IRSSWrapper\importLocalFile(), 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().

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.
+ 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.

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

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,
56  self::checkPossiblePath($web, $absolute_path), self::checkPossiblePath(
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
64  ) => Location::CUSTOMIZING,
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  }
+ 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.

References CLIENT_DATA_DIR, CLIENT_ID, CLIENT_WEB_DIR, and ILIAS_WEB_DIR.

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_DATA_DIR
Definition: constants.php:46
const CLIENT_ID
Definition: constants.php:41
const CLIENT_WEB_DIR
Definition: constants.php:47
const ILIAS_WEB_DIR
Definition: constants.php:45

◆ 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  }

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