php-vfs icon indicating copy to clipboard operation
php-vfs copied to clipboard

Add support for realpath

Open twifty opened this issue 8 years ago • 1 comments

I just came across the realpath issue while testing.

Would it be possible to add a static function to, perhaps, Wrapper which handle the paths for us? To work around the issue, I replaced the realpath global function with a namespaced alternative:

namespace Twifty\Composer { // The namespace from where realpath is called
    function realpath ($path) {
        $parts = preg_split('#://#', $path);
        
        if (1 === count($parts)) {
            return \realpath($path);
        }
        
        $wrapper = new \VirtualFileSystem\Wrapper();
        $file = $wrapper->getContainerFromContext($path)->nodeAt($parts[1]);
        
        if ($file instanceof \VirtualFileSystem\Structure\Link) {
            return $parts[0].':/'.$file->getDestination();
        }
        
        return $parts[0].':/'.$file->path();
    }
};

Luckily the required methods are public, but it would be nice if Wrapper handled the internals then I could:

namespace Twifty\Composer {
    function realpath ($path) {
        return \VirtualFileSystem\Wrapper::realpath($path);
    }
};

twifty avatar Jun 01 '17 07:06 twifty

any updates on this?

QusaiFarraj avatar May 02 '18 17:05 QusaiFarraj