ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ILIAS\Filesystem\Util\LegacyPathHelper Class Reference

Class LegacyPathHelper. More...

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

Static Public Member Functions

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

Static Private Member Functions

static resolveRelativePath ($possible_path, $absolute_path)
 
static checkPossiblePath ($possible_path, $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 18 of file LegacyPathHelper.php.

Member Function Documentation

◆ checkPossiblePath()

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

Definition at line 144 of file LegacyPathHelper.php.

145  {
146  $real_possible_path = realpath($possible_path);
147 
148  switch (true) {
149  case $possible_path === $absolute_path:
150  return true;
151  case $real_possible_path === $absolute_path:
152  return true;
153  case strpos($absolute_path, $possible_path) === 0:
154  return true;
155  case strpos($absolute_path, $real_possible_path) === 0:
156  return true;
157  default:
158  return false;
159  }
160  }

◆ createRelativePath()

static ILIAS\Filesystem\Util\LegacyPathHelper::createRelativePath (   $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 80 of file LegacyPathHelper.php.

Referenced by ILIAS\File\Sanitation\FilePathSanitizer\__construct(), ilFileSystemAbstractionStorage\createRelativePathForFileSystem(), ILIAS\Filesystem\Util\LegacyPathHelperTest\testCreateRelativePathWithInvalidTargetWhichShouldFail(), ILIAS\Filesystem\Util\LegacyPathHelperTest\testCreateRelativePathWithStorageTargetWhichShouldSucceed(), and ILIAS\Filesystem\Util\LegacyPathHelperTest\testCreateRelativePathWithWebTargetWhichShouldSucceed().

81  {
82  list(
83  $web, $webRelativeWithLeadingDot, $webRelativeWithoutLeadingDot, $storage, $customizing, $customizingRelativeWithLeadingDot, $libs, $libsRelativeWithLeadingDot, $temp
84  )
85  = self::listPaths();
86 
87  switch (true) {
88  // web without ./
89  case self::checkPossiblePath($webRelativeWithoutLeadingDot, $absolute_path):
90  return self::resolveRelativePath($webRelativeWithoutLeadingDot, $absolute_path);
91  // web with ./
92  case self::checkPossiblePath($webRelativeWithLeadingDot, $absolute_path):
93  return self::resolveRelativePath($webRelativeWithLeadingDot, $absolute_path);
94  // web/
95  case self::checkPossiblePath($web, $absolute_path):
96  return self::resolveRelativePath($web, $absolute_path);
97  // temp/
98  case self::checkPossiblePath($temp, $absolute_path):
99  return self::resolveRelativePath($temp, $absolute_path);
100  // iliasdata/
101  case self::checkPossiblePath($storage, $absolute_path):
102  return self::resolveRelativePath($storage, $absolute_path);
103  // Customizing/
104  case self::checkPossiblePath($customizing, $absolute_path):
105  return self::resolveRelativePath($customizing, $absolute_path);
106  // ./Customizing/
107  case self::checkPossiblePath($customizingRelativeWithLeadingDot, $absolute_path):
108  return self::resolveRelativePath($customizingRelativeWithLeadingDot, $absolute_path);
109  // libs/
110  case self::checkPossiblePath($libs, $absolute_path):
111  // ./libs
112  case self::checkPossiblePath($libsRelativeWithLeadingDot, $absolute_path):
113  return self::resolveRelativePath($libsRelativeWithLeadingDot, $absolute_path);
114  default:
115  throw new \InvalidArgumentException("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$absolute_path}'");
116  }
117  }
static resolveRelativePath($possible_path, $absolute_path)
static checkPossiblePath($possible_path, $absolute_path)
+ Here is the caller graph for this function:

◆ deriveFilesystemFrom()

static ILIAS\Filesystem\Util\LegacyPathHelper::deriveFilesystemFrom (   $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 36 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().

37  {
38  list(
39  $web, $webRelativeWithLeadingDot, $webRelativeWithoutLeadingDot, $storage, $customizing, $customizingRelativeWithLeadingDot, $libs, $libsRelativeWithLeadingDot, $temp
40  )
41  = self::listPaths();
42 
43  switch (true) {
44  case self::checkPossiblePath($temp, $absolute_path):
45  return self::filesystems()->temp();
46  case self::checkPossiblePath($web, $absolute_path):
47  return self::filesystems()->web();
48  case self::checkPossiblePath($webRelativeWithLeadingDot, $absolute_path):
49  return self::filesystems()->web();
50  case self::checkPossiblePath($webRelativeWithoutLeadingDot, $absolute_path):
51  return self::filesystems()->web();
52  case self::checkPossiblePath($storage, $absolute_path):
53  return self::filesystems()->storage();
54  case self::checkPossiblePath($customizing, $absolute_path):
55  return self::filesystems()->customizing();
56  case self::checkPossiblePath($customizingRelativeWithLeadingDot, $absolute_path):
57  return self::filesystems()->customizing();
58  case self::checkPossiblePath($libs, $absolute_path):
59  return self::filesystems()->libs();
60  case self::checkPossiblePath($libsRelativeWithLeadingDot, $absolute_path):
61  return self::filesystems()->libs();
62  default:
63  throw new \InvalidArgumentException("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$absolute_path}'");
64  }
65  }
static filesystems()
Returns the loaded filesystems.
+ 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 166 of file LegacyPathHelper.php.

References array.

167  {
168  $web = CLIENT_WEB_DIR;
169  $webRelativeWithLeadingDot = './' . ILIAS_WEB_DIR . '/' . CLIENT_ID;
170  $webRelativeWithoutLeadingDot = ILIAS_WEB_DIR . '/' . CLIENT_ID;
171  $storage = CLIENT_DATA_DIR;
172  $customizing = ILIAS_ABSOLUTE_PATH . '/Customizing';
173  $customizingRelativeWithLeadingDot = './Customizing';
174  $libs = ILIAS_ABSOLUTE_PATH . '/libs';
175  $libsRelativeWithLeadingDot = "./libs";
176  $temp = CLIENT_DATA_DIR . "/temp";
177 
178  return array($web, $webRelativeWithLeadingDot, $webRelativeWithoutLeadingDot, $storage, $customizing, $customizingRelativeWithLeadingDot, $libs, $libsRelativeWithLeadingDot, $temp);
179  }
Create styles array
The data for the language used.

◆ resolveRelativePath()

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

Definition at line 120 of file LegacyPathHelper.php.

121  {
122  $real_possible_path = realpath($possible_path);
123 
124  switch (true) {
125  case $possible_path === $absolute_path:
126  case $real_possible_path === $absolute_path:
127  return "";
128  case strpos($absolute_path, $possible_path) === 0:
129  return substr($absolute_path, strlen($possible_path) + 1); //also remove the trailing slash
130  case strpos($absolute_path, $real_possible_path) === 0:
131  return substr($absolute_path, strlen($real_possible_path) + 1); //also remove the trailing slash
132  default:
133  throw new \InvalidArgumentException("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$absolute_path}'");
134  }
135  }

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