public static function realpath($path)
{
// Support the path replacement of ~ with the user's home directory.
if (substr($path, 0, 2) === '~/') {
$homeDir = getenv('HOME');
if ($homeDir !== false) {
$path = $homeDir . substr($path, 1);
}
}
// No extra work needed if this is not a phar file.
if (self::isPharFile($path) === false) {
return realpath($path);
}
// Before trying to break down the file path,
// check if it exists first because it will mostly not
// change after running the below code.
if (file_exists($path) === true) {
return $path;
}
$phar = Phar::running(false);
$extra = str_replace('phar://' . $phar, '', $path);
$path = realpath($phar);
if ($path === false) {
return false;
}
$path = 'phar://' . $path . $extra;
if (file_exists($path) === true) {
return $path;
}
return false;
}