src/fs/entity/EntityAbstract.php
public function getRelativePath(string $path): string
    {
        $from = $this->path;

        $fromParts = explode("/", $from);
        $toParts = explode("/", $path);
        $max = max(count($fromParts), count($toParts));
        for ($i=0; $i<$max; $i++) {
            if (
                !isset($fromParts[$i]) ||
                !isset($toParts[$i]) ||
                $fromParts[$i] !== $toParts[$i]
            ) {
                break;
            }
        }

        $len = count($fromParts) - $i - 1;
        $path = array_slice($toParts, $i);
        if ($len < 0) {
            return implode("/", $path);
        }

        return str_repeat("../", $len).implode("/", $path);
    }
public function getRelativePath(string $path): string
    {
        $from = $this->path;

        $fromParts = explode("/", $from);
        $toParts = explode("/", $path);
        $max = max(count($fromParts), count($toParts));
        for ($i=0; $i<$max; $i++) {
            if (
                !isset($fromParts[$i]) ||
                !isset($toParts[$i]) ||
                $fromParts[$i] !== $toParts[$i]
            ) {
                break;
            }
        }

        $len = count($fromParts) - $i - 1;
        $path = array_slice($toParts, $i);
        if ($len < 0) {
            return implode("/", $path);
        }

        return str_repeat("../", $len).implode("/", $path);
    }
public function getRelativePath ( string $ path ) : string { $ from = $ this -> path ; $ fromParts = explode ( "/" , $ from ) ; $ toParts = explode ( "/" , $ path ) ; $ max = max ( count ( $ fromParts ) , count ( $ toParts ) ) ; for ( $ i = 0 ; $ i < $ max ; $ i ++ ) { if ( ! isset ( $ fromParts [ $ i ] ) || ! isset ( $ toParts [ $ i ] ) || $ fromParts [ $ i ] !== $ toParts [ $ i ] ) { break ; } } $ len = count ( $ fromParts ) - $ i - 1 ; $ path = array_slice ( $ toParts , $ i ) ; if ( $ len < 0 ) { return implode ( "/" , $ path ) ; } return str_repeat ( "../" , $ len ) . implode ( "/" , $ path ) ; }
Get the relative path from the current path to another

@param string $path
@return string
Get the relative path from the current path to another