Kwf/ComposerExtraAssets/LinkWriter.php
/**
     * Given an existing path, convert it to a path relative to a given starting path.
     * Function borrowed to Symfony's Filesystem. Thanks pals.
     *
     * @param string $endPath   Absolute path of target
     * @param string $startPath Absolute path where traversal begins
     *
     * @return string Path of target relative to starting path
     */
Given an existing path, convert it to a path relative to a given starting path.
Function borrowed to Symfony's Filesystem. Thanks pals.

@param string $endPath   Absolute path of target
@param string $startPath Absolute path where traversal begins

@return string Path of target relative to starting path
Given an existing path convert it to a path relative to a given starting path . Function borrowed to Symfony ' s Filesystem . Thanks pals . @param string $endPath Absolute path of target @param string $startPath Absolute path where traversal begins @return string Path of target relative to starting path
private function makePathRelative($endPath, $startPath)
    {
        if ('\\' === DIRECTORY_SEPARATOR) {
            $endPath = strtr($endPath, '\\', '/');
            $startPath = strtr($startPath, '\\', '/');
        }
        $startPathArr = explode('/', trim($startPath, '/'));
        $endPathArr = explode('/', trim($endPath, '/'));
        $index = 0;
        while (isset($startPathArr[$index]) && isset($endPathArr[$index]) && $startPathArr[$index] === $endPathArr[$index]) {
            $index++;
        }
        $depth = count($startPathArr) - $index;
        $traverser = str_repeat('../', $depth);
        $endPathRemainder = implode('/', array_slice($endPathArr, $index));
        $relativePath = $traverser.('' !== $endPathRemainder ? $endPathRemainder.'/' : '');
        return '' === $relativePath ? './' : $relativePath;
    }
private function makePathRelative ( $ endPath , $ startPath ) { if ( '\\' === DIRECTORY_SEPARATOR ) { $ endPath = strtr ( $ endPath , '\\' , '/' ) ; $ startPath = strtr ( $ startPath , '\\' , '/' ) ; } $ startPathArr = explode ( '/' , trim ( $ startPath , '/' ) ) ; $ endPathArr = explode ( '/' , trim ( $ endPath , '/' ) ) ; $ index = 0 ; while ( isset ( $ startPathArr [ $ index ] ) && isset ( $ endPathArr [ $ index ] ) && $ startPathArr [ $ index ] === $ endPathArr [ $ index ] ) { $ index ++ ; } $ depth = count ( $ startPathArr ) - $ index ; $ traverser = str_repeat ( '../' , $ depth ) ; $ endPathRemainder = implode ( '/' , array_slice ( $ endPathArr , $ index ) ) ; $ relativePath = $ traverser . ( '' !== $ endPathRemainder ? $ endPathRemainder . '/' : '' ) ; return '' === $ relativePath ? './' : $ relativePath ; }
Given an existing path, convert it to a path relative to a given starting path.
Given an existing path convert it to a path relative to a given starting path .
// Normalize separators on Windows // Split the paths into arrays // Find for which directory the common path stops // Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels) // Repeated "../" for each level need to reach the common path // Construct $endPath from traversing to the common path, then to the remaining $endPath