Todaymade\Daux\DauxHelper::isAbsolutePath PHP Method

isAbsolutePath() public static method

public static isAbsolutePath ( $path )
    public static function isAbsolutePath($path)
    {
        if (!is_string($path)) {
            $mess = sprintf('String expected but was given %s', gettype($path));
            throw new \InvalidArgumentException($mess);
        }
        if (!ctype_print($path)) {
            $mess = 'Path can NOT have non-printable characters or be empty';
            throw new \DomainException($mess);
        }
        // Optional wrapper(s).
        $regExp = '%^(?<wrappers>(?:[[:print:]]{2,}://)*)';
        // Optional root prefix.
        $regExp .= '(?<root>(?:[[:alpha:]]:/|/)?)';
        // Actual path.
        $regExp .= '(?<path>(?:[[:print:]]*))$%';
        $parts = [];
        if (!preg_match($regExp, $path, $parts)) {
            $mess = sprintf('Path is NOT valid, was given %s', $path);
            throw new \DomainException($mess);
        }
        return '' !== $parts['root'];
    }

Usage Example

Beispiel #1
0
 public function normalizeDocumentationPath($path)
 {
     // When running through `daux --serve` we set an environment variable to know where we started from
     $env = getenv('DAUX_SOURCE');
     if ($env && is_dir($env)) {
         return $env;
     }
     if (is_dir($path)) {
         if (DauxHelper::isAbsolutePath($path)) {
             return $path;
         }
         return getcwd() . '/' . $path;
     }
     throw new Exception('The Docs directory does not exist. Check the path again : ' . $path);
 }