New function to help resolve not-found files/directories (#217)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems.
This commit is contained in:
parent
e241f729ce
commit
0c28d683f5
@ -236,4 +236,31 @@ abstract class FileUtil {
|
||||
public static function isHiddenFile($fileName) {
|
||||
return (substr($fileName, 0, 1) === '.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortens a path.
|
||||
* Opposed to realpath, it follows symbolic links.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public static function shortenPath(string $path) {
|
||||
$root = substr($path, 0, 1) === '/';
|
||||
$path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
|
||||
$parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
|
||||
$absolutes = array();
|
||||
foreach ($parts as $part) {
|
||||
if ('.' === $part)
|
||||
continue;
|
||||
|
||||
if ('..' === $part)
|
||||
array_pop($absolutes);
|
||||
else
|
||||
array_push($absolutes, $part);
|
||||
}
|
||||
$path = implode(DIRECTORY_SEPARATOR, $absolutes);
|
||||
if ($root)
|
||||
$path = '/'.$path;
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user