mirror of
https://github.com/danog/psalm.git
synced 2024-12-14 02:07:37 +01:00
8534955572
Since functions defined in files referenced in 'files' section in composer autoload config are automatically loaded when composer autoloader is included (for example when Psalm is installed into project vendors), it's good idea to keep them namespaced. Otherwise it would prevent dependents to declare their own functions in the global namespace with the same names.
34 lines
611 B
PHP
34 lines
611 B
PHP
<?php
|
|
namespace Psalm;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
/**
|
|
* @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;
|
|
}
|