Kint::shortenPath PHP Method

shortenPath() public static method

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.
public static shortenPath ( string $file ) : string
$file string
return string
    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;
    }

Usage Example

示例#1
0
 public function parse(&$variable)
 {
     if (!$variable instanceof Closure) {
         return false;
     }
     $this->name = 'Closure';
     $reflection = new ReflectionFunction($variable);
     $ret = array('Parameters' => array());
     if ($val = $reflection->getParameters()) {
         foreach ($val as $parameter) {
             // todo http://php.net/manual/en/class.reflectionparameter.php
             $ret['Parameters'][] = $parameter->name;
         }
     }
     if ($val = $reflection->getStaticVariables()) {
         $ret['Uses'] = $val;
     }
     if (method_exists($reflection, 'getClousureThis') && ($val = $reflection->getClosureThis())) {
         $ret['Uses']['$this'] = $val;
     }
     if ($val = $reflection->getFileName()) {
         $this->value = Kint::shortenPath($val) . ':' . $reflection->getStartLine();
     }
     return $ret;
 }
All Usage Examples Of Kint::shortenPath