public static function getDirectory($path)
{
if ('' === $path) {
return '';
}
$path = static::canonicalize($path);
// Maintain scheme
if (false !== ($pos = strpos($path, '://'))) {
$scheme = substr($path, 0, $pos + 3);
$path = substr($path, $pos + 3);
} else {
$scheme = '';
}
if (false !== ($pos = strrpos($path, '/'))) {
// Directory equals root directory "/"
if (0 === $pos) {
return $scheme . '/';
}
// Directory equals Windows root "C:/"
if (2 === $pos && ctype_alpha($path[0]) && ':' === $path[1]) {
return $scheme . substr($path, 0, 3);
}
return $scheme . substr($path, 0, $pos);
}
return '';
}