public static function shortenPath($file)
{
$file = str_replace('\\', '/', $file);
$shortenedName = $file;
$replaced = false;
if (is_array(self::$appRootDirs)) {
foreach (self::$appRootDirs as $path => $replaceString) {
if (empty($path)) {
continue;
}
$path = str_replace('\\', '/', $path);
if (strpos($file, $path) === 0) {
$shortenedName = $replaceString . substr($file, strlen($path));
$replaced = true;
break;
}
}
}
# fallback to find common path with Kint dir
if (!$replaced) {
$pathParts = explode('/', str_replace('\\', '/', KINT_DIR));
$fileParts = explode('/', $file);
$i = 0;
foreach ($fileParts as $i => $filePart) {
if (!isset($pathParts[$i]) || $pathParts[$i] !== $filePart) {
break;
}
}
$shortenedName = ($i ? '.../' : '') . implode('/', array_slice($fileParts, $i));
}
return $shortenedName;
}