public static function relativeTo($from, $to) {
        if (static::isRelative($from) || static::isRelative($to)) {
            throw new InvalidArgumentException('Cannot determine relative path without two absolute paths');
        }

        $ds = static::SEPARATOR;
        $from = explode($ds, static::ds($from, true));
        $to = explode($ds, static::ds($to, true));
        $relative = $to;

        foreach ($from as $depth => $dir) {
            // Find first non-matching dir and ignore it
            if ($dir === $to[$depth]) {
                array_shift($relative);

            // Get count of remaining dirs to $from
            } else {
                $remaining = count($from) - $depth;

                // Add traversals up to first matching dir
                if ($remaining > 1) {
                    $padLength = (count($relative) + $remaining - 1) * -1;
                    $relative = array_pad($relative, $padLength, '..');
                    break;
                } else {
                    $relative[0] = '.' . $ds . $relative[0];
                }
            }
        }

        if (!$relative) {
            return '.' . $ds;
        }

        return implode($ds, $relative);
    }
public static function relativeTo($from, $to) {
        if (static::isRelative($from) || static::isRelative($to)) {
            throw new InvalidArgumentException('Cannot determine relative path without two absolute paths');
        }

        $ds = static::SEPARATOR;
        $from = explode($ds, static::ds($from, true));
        $to = explode($ds, static::ds($to, true));
        $relative = $to;

        foreach ($from as $depth => $dir) {
            // Find first non-matching dir and ignore it
            if ($dir === $to[$depth]) {
                array_shift($relative);

            // Get count of remaining dirs to $from
            } else {
                $remaining = count($from) - $depth;

                // Add traversals up to first matching dir
                if ($remaining > 1) {
                    $padLength = (count($relative) + $remaining - 1) * -1;
                    $relative = array_pad($relative, $padLength, '..');
                    break;
                } else {
                    $relative[0] = '.' . $ds . $relative[0];
                }
            }
        }

        if (!$relative) {
            return '.' . $ds;
        }

        return implode($ds, $relative);
    }
public static function relativeTo ( $ from , $ to ) { if ( static :: isRelative ( $ from ) || static :: isRelative ( $ to ) ) { throw new InvalidArgumentException ( 'Cannot determine relative path without two absolute paths' ) ; } $ ds = static :: SEPARATOR ; $ from = explode ( $ ds , static :: ds ( $ from , true ) ) ; $ to = explode ( $ ds , static :: ds ( $ to , true ) ) ; $ relative = $ to ; foreach ( $ from as $ depth => $ dir ) { // Find first non-matching dir and ignore it if ( $ dir === $ to [ $ depth ] ) { array_shift ( $ relative ) ; // Get count of remaining dirs to $from } else { $ remaining = count ( $ from ) - $ depth ; // Add traversals up to first matching dir if ( $ remaining > 1 ) { $ padLength = ( count ( $ relative ) + $ remaining - 1 ) * - 1 ; $ relative = array_pad ( $ relative , $ padLength , '..' ) ; break ; } else { $ relative [ 0 ] = '.' . $ ds . $ relative [ 0 ] ; } } } if ( ! $ relative ) { return '.' . $ ds ; } return implode ( $ ds , $ relative ) ; }
Determine the relative path between two absolute paths.

@param string $from
@param string $to
@return string
@throws \Titon\Utility\Exception\InvalidArgumentException
Determine the relative path between two absolute paths .