1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-14 18:36:58 +01:00
psalm/src/functions.php
Bruce Weirdan 8534955572 Namespace autoloaded functions (#1724)
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.
2019-06-02 11:23:25 -04:00

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;
}