2019-06-01 14:26:22 +02:00
|
|
|
<?php
|
2019-06-02 17:23:25 +02:00
|
|
|
namespace Psalm;
|
|
|
|
|
|
|
|
use InvalidArgumentException;
|
2019-06-26 22:52:29 +02:00
|
|
|
use function preg_match;
|
|
|
|
use function sprintf;
|
2019-06-02 17:23:25 +02:00
|
|
|
|
2019-06-01 14:26:22 +02:00
|
|
|
/**
|
|
|
|
* @param string $path
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function isAbsolutePath($path)
|
|
|
|
{
|
|
|
|
// Optional wrapper(s).
|
|
|
|
$regex = '%^(?<wrappers>(?:[[:print:]]{2,}://)*)';
|
|
|
|
|
|
|
|
// Optional root prefix.
|
2019-07-08 01:06:31 +02:00
|
|
|
$regex .= '(?<root>(?:[[:alpha:]]:[\\\/]|[\\\/])?)';
|
2019-06-01 14:26:22 +02:00
|
|
|
|
|
|
|
// Actual path.
|
|
|
|
$regex .= '(?<path>(?:[[:print:]]*))$%';
|
|
|
|
|
|
|
|
$parts = [];
|
|
|
|
|
|
|
|
if (!preg_match($regex, $path, $parts)) {
|
|
|
|
throw new InvalidArgumentException(sprintf('Path is not valid, "%s" given.', $path));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('' !== $parts['root']) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|