<?php
+use Webmozart\PathUtil\Path;
+
/**
* @param string $path
* @return null|string
return null;
}
- if (realpath($path)) {
+ if (strpos($path, 'phar://')===0) {
return $path;
}
- return transformToRealPath($path);
-}
-
-/**
- * @param $path
- * @return string
- */
-function transformToRealPath($path)
-{
- if (strpos($path, '~') === 0) {
- $home = rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '/');
- $path = preg_replace('/~/', $home, $path, 1);
- }
-
- if (!(strpos($path, '/') === 0)) {
- $path = sprintf('%s/%s', getcwd(), $path);
+ if (realpath($path)) {
+ return $path;
}
- return realpath($path);
+ return Path::canonicalize($path);
}