ILIAS  release_7 Revision v7.30-3-g800a261c036
ILIAS\Filesystem\Util\LegacyPathHelper Class Reference

Class LegacyPathHelper 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 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

Class LegacyPathHelper 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
Since
5.3
Version
1.0.0

Definition at line 17 of file LegacyPathHelper.php.

Member Function Documentation

◆ checkPossiblePath()

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

Definition at line 158 of file LegacyPathHelper.php.

158  : bool
159  {
160  $real_possible_path = realpath($possible_path);
161 
162  switch (true) {
163  case $possible_path === $absolute_path:
164  return true;
165  case $real_possible_path === $absolute_path:
166  return true;
167  case is_string($possible_path) && strpos($absolute_path, $possible_path) === 0:
168  return true;
169  case is_string($real_possible_path) && strpos($absolute_path, $real_possible_path) === 0:
170  return true;
171  default:
172  return false;
173  }
174  }

◆ 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 81 of file LegacyPathHelper.php.

Referenced by ILIAS\File\Sanitation\FilePathSanitizer\__construct(), LegacyPathHelperHelper\createRelativePath(), ilFileSystemAbstractionStorage\createRelativePathForFileSystem(), ILIAS\ResourceStorage\StorageHandler\FileSystemBased\AbstractFileSystemStorageHandler\storeStream(), ILIAS\Filesystem\Util\LegacyPathHelperTest\testCreateRelativePathWithInvalidTargetWhichShouldFail(), ILIAS\Filesystem\Util\LegacyPathHelperTest\testCreateRelativePathWithStorageTargetWhichShouldSucceed(), and ILIAS\Filesystem\Util\LegacyPathHelperTest\testCreateRelativePathWithWebTargetWhichShouldSucceed().

81  : string
82  {
83  list(
84  $web,
85  $webRelativeWithLeadingDot,
86  $webRelativeWithoutLeadingDot,
87  $storage,
88  $customizing,
89  $customizingRelativeWithLeadingDot,
90  $libs,
91  $libsRelativeWithLeadingDot,
92  $temp,
93  $nodeModules,
94  $nodeModulesWithLeadingDot
95  ) = self::listPaths();
96 
97  switch (true) {
98  // web without ./
99  case self::checkPossiblePath($webRelativeWithoutLeadingDot, $absolute_path):
100  return self::resolveRelativePath($webRelativeWithoutLeadingDot, $absolute_path);
101  // web with ./
102  case self::checkPossiblePath($webRelativeWithLeadingDot, $absolute_path):
103  return self::resolveRelativePath($webRelativeWithLeadingDot, $absolute_path);
104  // web/
105  case self::checkPossiblePath($web, $absolute_path):
106  return self::resolveRelativePath($web, $absolute_path);
107  // temp/
108  case self::checkPossiblePath($temp, $absolute_path):
109  return self::resolveRelativePath($temp, $absolute_path);
110  // iliasdata/
111  case self::checkPossiblePath($storage, $absolute_path):
112  return self::resolveRelativePath($storage, $absolute_path);
113  // Customizing/
114  case self::checkPossiblePath($customizing, $absolute_path):
115  return self::resolveRelativePath($customizing, $absolute_path);
116  // ./Customizing/
117  case self::checkPossiblePath($customizingRelativeWithLeadingDot, $absolute_path):
118  return self::resolveRelativePath($customizingRelativeWithLeadingDot, $absolute_path);
119  // libs/
120  case self::checkPossiblePath($libs, $absolute_path):
121  // ./libs
122  case self::checkPossiblePath($libsRelativeWithLeadingDot, $absolute_path):
123  return self::resolveRelativePath($libsRelativeWithLeadingDot, $absolute_path);
124  // node_modules/
125  case self::checkPossiblePath($nodeModules, $absolute_path):
126  // ./node_modules
127  case self::checkPossiblePath($nodeModulesWithLeadingDot, $absolute_path):
128  return self::resolveRelativePath($nodeModulesWithLeadingDot, $absolute_path);
129  default:
130  throw new \InvalidArgumentException("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$absolute_path}'");
131  }
132  }
static resolveRelativePath(string $possible_path, string $absolute_path)
static checkPossiblePath(string $possible_path, string $absolute_path)
+ 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 './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 29 of file LegacyPathHelper.php.

References ILIAS\Filesystem\filesystems().

Referenced by ILIAS\File\Sanitation\FilePathSanitizer\__construct(), 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().

29  : Filesystem
30  {
31  list(
32  $web,
33  $webRelativeWithLeadingDot,
34  $webRelativeWithoutLeadingDot,
35  $storage,
36  $customizing,
37  $customizingRelativeWithLeadingDot,
38  $libs,
39  $libsRelativeWithLeadingDot,
40  $temp,
41  $nodeModules,
42  $nodeModulesWithLeadingDot
43  ) = self::listPaths();
44 
45  switch (true) {
46  case self::checkPossiblePath($temp, $absolute_path):
47  return self::filesystems()->temp();
48  case self::checkPossiblePath($web, $absolute_path):
49  return self::filesystems()->web();
50  case self::checkPossiblePath($webRelativeWithLeadingDot, $absolute_path):
51  return self::filesystems()->web();
52  case self::checkPossiblePath($webRelativeWithoutLeadingDot, $absolute_path):
53  return self::filesystems()->web();
54  case self::checkPossiblePath($storage, $absolute_path):
55  return self::filesystems()->storage();
56  case self::checkPossiblePath($customizing, $absolute_path):
57  return self::filesystems()->customizing();
58  case self::checkPossiblePath($customizingRelativeWithLeadingDot, $absolute_path):
59  return self::filesystems()->customizing();
60  case self::checkPossiblePath($libs, $absolute_path):
61  return self::filesystems()->libs();
62  case self::checkPossiblePath($libsRelativeWithLeadingDot, $absolute_path):
63  return self::filesystems()->libs();
64  case self::checkPossiblePath($nodeModules, $absolute_path):
65  return self::filesystems()->nodeModules();
66  case self::checkPossiblePath($nodeModulesWithLeadingDot, $absolute_path):
67  return self::filesystems()->nodeModules();
68  default:
69  throw new \InvalidArgumentException("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$absolute_path}'");
70  }
71  }
static filesystems()
Returns the loaded filesystems.
Class FlySystemFileAccessTest disabled disabled disabled.
+ 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
array

Definition at line 179 of file LegacyPathHelper.php.

References CLIENT_DATA_DIR, CLIENT_ID, CLIENT_WEB_DIR, and ILIAS_WEB_DIR.

179  : array
180  {
181  $web = CLIENT_WEB_DIR;
182  $webRelativeWithLeadingDot = './' . ILIAS_WEB_DIR . '/' . CLIENT_ID;
183  $webRelativeWithoutLeadingDot = ILIAS_WEB_DIR . '/' . CLIENT_ID;
184  $storage = CLIENT_DATA_DIR;
185  $customizing = ILIAS_ABSOLUTE_PATH . '/Customizing';
186  $customizingRelativeWithLeadingDot = './Customizing';
187  $libs = ILIAS_ABSOLUTE_PATH . '/libs';
188  $libsRelativeWithLeadingDot = "./libs";
189  $temp = CLIENT_DATA_DIR . "/temp";
190  $nodeModules = ILIAS_ABSOLUTE_PATH . '/node_modules';
191  $nodeModulesWithLeadingDot = './node_modules';
192 
193  return array($web,
194  $webRelativeWithLeadingDot,
195  $webRelativeWithoutLeadingDot,
196  $storage,
197  $customizing,
198  $customizingRelativeWithLeadingDot,
199  $libs,
200  $libsRelativeWithLeadingDot,
201  $temp,
202  $nodeModules,
203  $nodeModulesWithLeadingDot
204  );
205  }
const CLIENT_DATA_DIR
Definition: constants.php:44
const CLIENT_ID
Definition: constants.php:39
const CLIENT_WEB_DIR
Definition: constants.php:45
const ILIAS_WEB_DIR
Definition: constants.php:43

◆ resolveRelativePath()

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

Definition at line 134 of file LegacyPathHelper.php.

134  : string
135  {
136  $real_possible_path = realpath($possible_path);
137 
138  switch (true) {
139  case $possible_path === $absolute_path:
140  case $real_possible_path === $absolute_path:
141  return "";
142  case strpos($absolute_path, $possible_path) === 0:
143  return substr($absolute_path,
144  strlen($possible_path) + 1); //also remove the trailing slash
145  case strpos($absolute_path, $real_possible_path) === 0:
146  return substr($absolute_path,
147  strlen($real_possible_path) + 1); //also remove the trailing slash
148  default:
149  throw new \InvalidArgumentException("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$absolute_path}'");
150  }
151  }

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