ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ILIAS\Filesystem\Util\LegacyPathHelper Class Reference

Class LegacyPathHelper. 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 19 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 145 of file LegacyPathHelper.php.

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

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

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

81 : string
82 {
83 list(
84 $web, $webRelativeWithLeadingDot, $webRelativeWithoutLeadingDot, $storage, $customizing, $customizingRelativeWithLeadingDot, $libs, $libsRelativeWithLeadingDot, $temp
85 )
87
88 switch (true) {
89 // web without ./
90 case self::checkPossiblePath($webRelativeWithoutLeadingDot, $absolute_path):
91 return self::resolveRelativePath($webRelativeWithoutLeadingDot, $absolute_path);
92 // web with ./
93 case self::checkPossiblePath($webRelativeWithLeadingDot, $absolute_path):
94 return self::resolveRelativePath($webRelativeWithLeadingDot, $absolute_path);
95 // web/
96 case self::checkPossiblePath($web, $absolute_path):
97 return self::resolveRelativePath($web, $absolute_path);
98 // temp/
99 case self::checkPossiblePath($temp, $absolute_path):
100 return self::resolveRelativePath($temp, $absolute_path);
101 // iliasdata/
102 case self::checkPossiblePath($storage, $absolute_path):
103 return self::resolveRelativePath($storage, $absolute_path);
104 // Customizing/
105 case self::checkPossiblePath($customizing, $absolute_path):
106 return self::resolveRelativePath($customizing, $absolute_path);
107 // ./Customizing/
108 case self::checkPossiblePath($customizingRelativeWithLeadingDot, $absolute_path):
109 return self::resolveRelativePath($customizingRelativeWithLeadingDot, $absolute_path);
110 // libs/
111 case self::checkPossiblePath($libs, $absolute_path):
112 // ./libs
113 case self::checkPossiblePath($libsRelativeWithLeadingDot, $absolute_path):
114 return self::resolveRelativePath($libsRelativeWithLeadingDot, $absolute_path);
115 default:
116 throw new \InvalidArgumentException("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$absolute_path}'");
117 }
118 }
static checkPossiblePath(string $possible_path, string $absolute_path)
static resolveRelativePath(string $possible_path, string $absolute_path)
return['Universal Coordinated Time'=> 'UTC', 'Casablanca, Monrovia'=> 'Africa/Casablanca', 'Greenwich Mean Time:Dublin, Edinburgh, Lisbon, London'=> 'Europe/Lisbon', 'Greenwich Mean Time;Dublin, Edinburgh, London'=> 'Europe/London', 'Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna'=> 'Europe/Berlin', 'Belgrade, Pozsony, Budapest, Ljubljana, Prague'=> 'Europe/Prague', 'Brussels, Copenhagen, Madrid, Paris'=> 'Europe/Paris', 'Paris, Madrid, Brussels, Copenhagen'=> 'Europe/Paris', 'Prague, Central Europe'=> 'Europe/Prague', 'Sarajevo, Skopje, Sofija, Vilnius, Warsaw, Zagreb'=> 'Europe/Sarajevo', 'West Central Africa'=> 'Africa/Luanda', 'Athens, Istanbul, Minsk'=> 'Europe/Athens', 'Bucharest'=> 'Europe/Bucharest', 'Cairo'=> 'Africa/Cairo', 'Harare, Pretoria'=> 'Africa/Harare', 'Helsinki, Riga, Tallinn'=> 'Europe/Helsinki', 'Israel, Jerusalem Standard Time'=> 'Asia/Jerusalem', 'Baghdad'=> 'Asia/Baghdad', 'Arab, Kuwait, Riyadh'=> 'Asia/Kuwait', 'Moscow, St. Petersburg, Volgograd'=> 'Europe/Moscow', 'East Africa, Nairobi'=> 'Africa/Nairobi', 'Tehran'=> 'Asia/Tehran', 'Abu Dhabi, Muscat'=> 'Asia/Muscat', 'Baku, Tbilisi, Yerevan'=> 'Asia/Baku', 'Kabul'=> 'Asia/Kabul', 'Ekaterinburg'=> 'Asia/Yekaterinburg', 'Islamabad, Karachi, Tashkent'=> 'Asia/Karachi', 'Kolkata, Chennai, Mumbai, New Delhi, India Standard Time'=> 'Asia/Calcutta', 'Kathmandu, Nepal'=> 'Asia/Kathmandu', 'Almaty, Novosibirsk, North Central Asia'=> 'Asia/Almaty', 'Astana, Dhaka'=> 'Asia/Dhaka', 'Sri Jayawardenepura, Sri Lanka'=> 'Asia/Colombo', 'Rangoon'=> 'Asia/Rangoon', 'Bangkok, Hanoi, Jakarta'=> 'Asia/Bangkok', 'Krasnoyarsk'=> 'Asia/Krasnoyarsk', 'Beijing, Chongqing, Hong Kong SAR, Urumqi'=> 'Asia/Shanghai', 'Irkutsk, Ulaan Bataar'=> 'Asia/Irkutsk', 'Kuala Lumpur, Singapore'=> 'Asia/Singapore', 'Perth, Western Australia'=> 'Australia/Perth', 'Taipei'=> 'Asia/Taipei', 'Osaka, Sapporo, Tokyo'=> 'Asia/Tokyo', 'Seoul, Korea Standard time'=> 'Asia/Seoul', 'Yakutsk'=> 'Asia/Yakutsk', 'Adelaide, Central Australia'=> 'Australia/Adelaide', 'Darwin'=> 'Australia/Darwin', 'Brisbane, East Australia'=> 'Australia/Brisbane', 'Canberra, Melbourne, Sydney, Hobart(year 2000 only)'=> 'Australia/Sydney', 'Guam, Port Moresby'=> 'Pacific/Guam', 'Hobart, Tasmania'=> 'Australia/Hobart', 'Vladivostok'=> 'Asia/Vladivostok', 'Magadan, Solomon Is., New Caledonia'=> 'Asia/Magadan', 'Auckland, Wellington'=> 'Pacific/Auckland', 'Fiji Islands, Kamchatka, Marshall Is.'=> 'Pacific/Fiji', 'Nuku\ 'alofa, Tonga'=> 'Pacific/Tongatapu', 'Azores'=> 'Atlantic/Azores', 'Cape Verde Is.'=> 'Atlantic/Cape_Verde', 'Mid-Atlantic'=> 'America/Noronha', 'Brasilia'=> 'America/Sao_Paulo', 'Buenos Aires'=> 'America/Argentina/Buenos_Aires', 'Greenland'=> 'America/Godthab', 'Newfoundland'=> 'America/St_Johns', 'Atlantic Time(Canada)'=> 'America/Halifax', 'Caracas, La Paz'=> 'America/Caracas', 'Santiago'=> 'America/Santiago', 'Bogota, Lima, Quito'=> 'America/Bogota', 'Eastern Time(US &Canada)'=> 'America/New_York', 'Indiana(East)'=> 'America/Indiana/Indianapolis', 'Central America'=> 'America/Guatemala', 'Central Time(US &Canada)'=> 'America/Chicago', 'Mexico City, Tegucigalpa'=> 'America/Mexico_City', 'Saskatchewan'=> 'America/Edmonton', 'Arizona'=> 'America/Phoenix', 'Mountain Time(US &Canada)'=> 'America/Denver', 'Pacific Time(US &Canada)'=> 'America/Los_Angeles', 'Pacific Time(US &Canada);Tijuana'=> 'America/Los_Angeles', 'Alaska'=> 'America/Anchorage', 'Hawaii'=> 'Pacific/Honolulu', 'Midway Island, Samoa'=> 'Pacific/Midway', 'Eniwetok, Kwajalein, Dateline Time'=> 'Pacific/Kwajalein',]
Microsoft exchange timezones Source: http://msdn.microsoft.com/en-us/library/ms988620%28v=exchg....

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

Referenced by ILIAS\File\Sanitation\FilePathSanitizer\__construct(), LegacyPathHelperHelper\createRelativePath(), ilFileSystemAbstractionStorage\createRelativePathForFileSystem(), ILIAS\File\Sanitation\FilePathSanitizer\sanitizeIfNeeded(), 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 37 of file LegacyPathHelper.php.

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

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

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().

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

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

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

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

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

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: