-
Notifications
You must be signed in to change notification settings - Fork 16
/
Path.php
72 lines (63 loc) · 1.91 KB
/
Path.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/*
* This file was imported from the webmozart/path-util package.
*
* (c) Bernhard Schussek <bschussek@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Webmozart\Glob;
/**
* Contains utility methods for handling path strings.
*
* The methods in this class are able to deal with both UNIX and Windows paths
* with both forward and backward slashes. All methods return normalized parts
* containing only forward slashes and no excess "." and ".." segments.
*
* @author Bernhard Schussek <bschussek@gmail.com>
* @author Thomas Schulz <mail@king2500.net>
*
* @internal this class was introduced to remove an external dependency, but is
* not part of the public API of this package: do not use it directly.
*/
abstract class Path
{
/**
* Returns whether a path is absolute.
*
* @param string $path A path string.
*
* @return bool Returns true if the path is absolute, false if it is
* relative or empty.
*/
public static function isAbsolute(string $path): bool
{
if ('' === $path) {
return false;
}
// Strip scheme
if (false !== ($pos = strpos($path, '://'))) {
$path = substr($path, $pos + 3);
}
// UNIX root "/" or "\" (Windows style)
if ('/' === $path[0] || '\\' === $path[0]) {
return true;
}
// Windows root
if (strlen($path) > 1 && ctype_alpha($path[0]) && ':' === $path[1]) {
// Special case: "C:"
if (2 === strlen($path)) {
return true;
}
// Normal case: "C:/ or "C:\"
if ('/' === $path[2] || '\\' === $path[2]) {
return true;
}
}
return false;
}
final private function __construct()
{
}
}