* * 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 * @author Thomas Schulz * * @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() { } }