php-vfs
php-vfs copied to clipboard
Add support for realpath
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);
}
};
any updates on this?