Webmozart\PathUtil\Path::isAbsolute PHP Method

isAbsolute() public static method

Returns whether a path is absolute.
Since: 1.0 Added method.
Since: 2.0 Method now fails if $path is not a string.
public static isAbsolute ( string $path ) : boolean
$path string A path string.
return boolean Returns true if the path is absolute, false if it is relative or empty.
    public static function isAbsolute($path)
    {
        if ('' === $path) {
            return false;
        }
        Assert::string($path, 'The path must be a string. Got: %s');
        // Strip scheme
        if (false !== ($pos = strpos($path, '://'))) {
            $path = substr($path, $pos + 3);
        }
        // UNIX root "/" or "\" (Windows style)
        if ('/' === $path[0] || '\\' === $path[0]) {
            return true;
        }
        // Windows root
        if (strlen($path) > 1 && ctype_alpha($path[0]) && ':' === $path[1]) {
            // Special case: "C:"
            if (2 === strlen($path)) {
                return true;
            }
            // Normal case: "C:/ or "C:\"
            if ('/' === $path[2] || '\\' === $path[2]) {
                return true;
            }
        }
        return false;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  *
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  * @throws \LogicException
  * @throws BadMethodCallException
  */
 public function load($resource, $type = null)
 {
     $path = $this->locator->locate($resource);
     $this->container->addResource(new FileResource($path));
     $file = new JsonFile($path);
     $content = $file->read();
     $extension = pathinfo($resource, PATHINFO_FILENAME);
     if (array_key_exists('parameters', $content)) {
         foreach ($content['parameters'] as $name => $parameter) {
             $this->container->setParameter($name, $parameter);
         }
         unset($content['parameters']);
     }
     if (array_key_exists('imports', $content)) {
         foreach ($content['imports'] as $import) {
             $importFilename = $import;
             if (!Path::isAbsolute($importFilename)) {
                 $importFilename = Path::join([dirname($path), $import]);
             }
             $this->import($importFilename, null, false, $file);
         }
         unset($content['imports']);
     }
     $this->container->loadFromExtension($extension, $content);
 }
All Usage Examples Of Webmozart\PathUtil\Path::isAbsolute