public function relativizePath($absolutePath): string
    {
        $absolutePath = $this->normalizeSlashes($absolutePath);

        // see if the path is even in the root
        if (false === strpos($absolutePath, $this->rootDirectory)) {
            return $absolutePath;
        }

        $absolutePath = $this->realPath($absolutePath);

        // str_replace but only the first occurrence
        $relativePath = ltrim(implode('', explode($this->rootDirectory, $absolutePath, 2)), '/');
        if (0 === strpos($relativePath, './')) {
            $relativePath = substr($relativePath, 2);
        }

        return is_dir($absolutePath) ? rtrim($relativePath, '/').'/' : $relativePath;
    }
public function relativizePath($absolutePath): string
    {
        $absolutePath = $this->normalizeSlashes($absolutePath);

        // see if the path is even in the root
        if (false === strpos($absolutePath, $this->rootDirectory)) {
            return $absolutePath;
        }

        $absolutePath = $this->realPath($absolutePath);

        // str_replace but only the first occurrence
        $relativePath = ltrim(implode('', explode($this->rootDirectory, $absolutePath, 2)), '/');
        if (0 === strpos($relativePath, './')) {
            $relativePath = substr($relativePath, 2);
        }

        return is_dir($absolutePath) ? rtrim($relativePath, '/').'/' : $relativePath;
    }
public function relativizePath ( $ absolutePath ) : string { $ absolutePath = $ this -> normalizeSlashes ( $ absolutePath ) ; // see if the path is even in the root if ( false === strpos ( $ absolutePath , $ this -> rootDirectory ) ) { return $ absolutePath ; } $ absolutePath = $ this -> realPath ( $ absolutePath ) ; // str_replace but only the first occurrence $ relativePath = ltrim ( implode ( '' , explode ( $ this -> rootDirectory , $ absolutePath , 2 ) ) , '/' ) ; if ( 0 === strpos ( $ relativePath , './' ) ) { $ relativePath = substr ( $ relativePath , 2 ) ; } return is_dir ( $ absolutePath ) ? rtrim ( $ relativePath , '/' ) . '/' : $ relativePath ; }
Attempts to make the path relative to the root directory.

@param string $absolutePath

@return string

@throws \Exception
Attempts to make the path relative to the root directory .