function Kint::shortenPath

* generic path display callback, can be configured in the settings; purpose is to show relevant path info and hide * as much of the path as possible. * *

Parameters

string $file: * * @return string

6 calls to Kint::shortenPath()
Kint::_parseTrace in kint/kint/Kint.class.php
kintParser::_parse_resource in kint/kint/inc/kintParser.class.php
Kint_Decorators_Plain::_buildCalleeString in kint/kint/decorators/plain.php
Kint_Decorators_Rich::_ideLink in kint/kint/decorators/rich.php
Kint_Objects_Closure::parse in kint/kint/parsers/objects/closure.php
* returns false or associative array - each key represents a tab in default view, values may be anything * *

... See full list

File

kint/kint/Kint.class.php, line 276

Class

Kint

Code

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;
}