2019-06-01 14:26:22 +02:00
|
|
|
<?php
|
2019-06-02 17:23:25 +02:00
|
|
|
namespace Psalm;
|
|
|
|
|
|
|
|
use InvalidArgumentException;
|
|
|
|
|
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.
|
|
|
|
$regex .= '(?<root>(?:[[:alpha:]]:/|/)?)';
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|