ILIAS  release_8 Revision v8.24
ILIAS\Filesystem\Util\LegacyPathHelper Class Reference

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

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 37 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 228 of file LegacyPathHelper.php.

228 : bool
229 {
230 $real_possible_path = realpath($possible_path);
231
232 switch (true) {
233 case $possible_path === $absolute_path:
234 return true;
235 case $real_possible_path === $absolute_path:
236 return true;
237 case is_string($possible_path) && strpos($absolute_path, $possible_path) === 0:
238 return true;
239 case is_string($real_possible_path) && strpos($absolute_path, $real_possible_path) === 0:
240 return true;
241 default:
242 return false;
243 }
244 }

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

144 : string
145 {
146 [
147 $web,
148 $webRelativeWithLeadingDot,
149 $webRelativeWithoutLeadingDot,
150 $storage,
151 $customizing,
152 $customizingRelativeWithLeadingDot,
153 $libs,
154 $libsRelativeWithLeadingDot,
155 $temp,
156 $nodeModules,
157 $nodeModulesWithLeadingDot
158 ] = self::listPaths();
159
160 switch (true) {
161 // web without ./
162 case self::checkPossiblePath($webRelativeWithoutLeadingDot, $absolute_path):
163 return self::resolveRelativePath($webRelativeWithoutLeadingDot, $absolute_path);
164 // web with ./
165 case self::checkPossiblePath($webRelativeWithLeadingDot, $absolute_path):
166 return self::resolveRelativePath($webRelativeWithLeadingDot, $absolute_path);
167 // web/
168 case self::checkPossiblePath($web, $absolute_path):
169 return self::resolveRelativePath($web, $absolute_path);
170 // temp/
171 case self::checkPossiblePath($temp, $absolute_path):
172 return self::resolveRelativePath($temp, $absolute_path);
173 // iliasdata/
174 case self::checkPossiblePath($storage, $absolute_path):
175 return self::resolveRelativePath($storage, $absolute_path);
176 // Customizing/
177 case self::checkPossiblePath($customizing, $absolute_path):
178 return self::resolveRelativePath($customizing, $absolute_path);
179 // ./Customizing/
180 case self::checkPossiblePath($customizingRelativeWithLeadingDot, $absolute_path):
181 return self::resolveRelativePath($customizingRelativeWithLeadingDot, $absolute_path);
182 // libs/
183 case self::checkPossiblePath($libs, $absolute_path):
184 // ./libs
185 case self::checkPossiblePath($libsRelativeWithLeadingDot, $absolute_path):
186 return self::resolveRelativePath($libsRelativeWithLeadingDot, $absolute_path);
187 // node_modules/
188 case self::checkPossiblePath($nodeModules, $absolute_path):
189 // ./node_modules
190 case self::checkPossiblePath($nodeModulesWithLeadingDot, $absolute_path):
191 return self::resolveRelativePath($nodeModulesWithLeadingDot, $absolute_path);
192 default:
193 throw new \InvalidArgumentException("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$absolute_path}'");
194 }
195 }
static checkPossiblePath(string $possible_path, string $absolute_path)
static resolveRelativePath(string $possible_path, string $absolute_path)
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']

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

Referenced by LegacyPathHelperHelper\createRelativePath(), ilFileSystemAbstractionStorage\createRelativePathForFileSystem(), 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 './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 87 of file LegacyPathHelper.php.

88 {
89 [
90 $web,
91 $webRelativeWithLeadingDot,
92 $webRelativeWithoutLeadingDot,
93 $storage,
94 $customizing,
95 $customizingRelativeWithLeadingDot,
96 $libs,
97 $libsRelativeWithLeadingDot,
98 $temp,
99 $nodeModules,
100 $nodeModulesWithLeadingDot
101 ] = self::listPaths();
102
103 switch (true) {
104 case self::checkPossiblePath($temp, $absolute_path):
105 return self::filesystems()->temp();
106 case self::checkPossiblePath($web, $absolute_path):
107 return self::filesystems()->web();
108 case self::checkPossiblePath($webRelativeWithLeadingDot, $absolute_path):
109 return self::filesystems()->web();
110 case self::checkPossiblePath($webRelativeWithoutLeadingDot, $absolute_path):
111 return self::filesystems()->web();
112 case self::checkPossiblePath($storage, $absolute_path):
113 return self::filesystems()->storage();
114 case self::checkPossiblePath($customizing, $absolute_path):
115 return self::filesystems()->customizing();
116 case self::checkPossiblePath($customizingRelativeWithLeadingDot, $absolute_path):
117 return self::filesystems()->customizing();
118 case self::checkPossiblePath($libs, $absolute_path):
119 return self::filesystems()->libs();
120 case self::checkPossiblePath($libsRelativeWithLeadingDot, $absolute_path):
121 return self::filesystems()->libs();
122 case self::checkPossiblePath($nodeModules, $absolute_path):
123 return self::filesystems()->nodeModules();
124 case self::checkPossiblePath($nodeModulesWithLeadingDot, $absolute_path):
125 return self::filesystems()->nodeModules();
126 default:
127 throw new \InvalidArgumentException("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$absolute_path}'");
128 }
129 }
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...
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 41 of file LegacyPathHelper.php.

41 : int
42 {
43 [
44 $web,
45 $webRelativeWithLeadingDot,
46 $webRelativeWithoutLeadingDot,
47 $storage,
48 $customizing,
49 $customizingRelativeWithLeadingDot,
50 $libs,
51 $libsRelativeWithLeadingDot,
52 $temp,
53 $nodeModules,
54 $nodeModulesWithLeadingDot
55 ] = self::listPaths();
56
57 switch (true) {
58 case self::checkPossiblePath($temp, $absolute_path):
59 return Location::TEMPORARY;
60 case self::checkPossiblePath($web, $absolute_path):
61 case self::checkPossiblePath($webRelativeWithLeadingDot, $absolute_path):
62 case self::checkPossiblePath($webRelativeWithoutLeadingDot, $absolute_path):
63 return Location::WEB;
64 case self::checkPossiblePath($storage, $absolute_path):
65 return Location::STORAGE;
66 case self::checkPossiblePath($customizing, $absolute_path):
67 case self::checkPossiblePath($customizingRelativeWithLeadingDot, $absolute_path):
68 return Location::CUSTOMIZING;
69 default:
70 throw new \InvalidArgumentException("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$absolute_path}'");
71 }
72 }

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
array

Definition at line 250 of file LegacyPathHelper.php.

250 : array
251 {
252 $web = CLIENT_WEB_DIR;
253 $webRelativeWithLeadingDot = './' . ILIAS_WEB_DIR . '/' . CLIENT_ID;
254 $webRelativeWithoutLeadingDot = ILIAS_WEB_DIR . '/' . CLIENT_ID;
255 $storage = CLIENT_DATA_DIR;
256 $customizing = ILIAS_ABSOLUTE_PATH . '/Customizing';
257 $customizingRelativeWithLeadingDot = './Customizing';
258 $libs = ILIAS_ABSOLUTE_PATH . '/libs';
259 $libsRelativeWithLeadingDot = "./libs";
260 $temp = CLIENT_DATA_DIR . "/temp";
261 $nodeModules = ILIAS_ABSOLUTE_PATH . '/node_modules';
262 $nodeModulesWithLeadingDot = './node_modules';
263
264 return array($web,
265 $webRelativeWithLeadingDot,
266 $webRelativeWithoutLeadingDot,
267 $storage,
268 $customizing,
269 $customizingRelativeWithLeadingDot,
270 $libs,
271 $libsRelativeWithLeadingDot,
272 $temp,
273 $nodeModules,
274 $nodeModulesWithLeadingDot
275 );
276 }
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 198 of file LegacyPathHelper.php.

198 : string
199 {
200 $real_possible_path = realpath($possible_path);
201
202 switch (true) {
203 case $possible_path === $absolute_path:
204 case $real_possible_path === $absolute_path:
205 return "";
206 case strpos($absolute_path, $possible_path) === 0:
207 return substr(
208 $absolute_path,
209 strlen($possible_path) + 1
210 ); //also remove the trailing slash
211 case strpos($absolute_path, $real_possible_path) === 0:
212 return substr(
213 $absolute_path,
214 strlen($real_possible_path) + 1
215 ); //also remove the trailing slash
216 default:
217 throw new \InvalidArgumentException("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$absolute_path}'");
218 }
219 }

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: