Parse a relative path using the base path if needed.

@param  string $path The path to resolve.
@throws InvalidArgumentException If the path is invalid.
@return string
481380
private function resolvePath($path)
    {
        if (!is_string($path)) {
            throw new InvalidArgumentException(
                'Path needs to be a string'
            );
        }

        $basePath = $this->basePath();
        $path = trim($path, '/\\');

        if ($basePath && strpos($path, $basePath) === false) {
            $path = $basePath.$path;
        }

        return $path;
    }
1370445
private function parsePath($path)
    {
        $info = pathinfo($path);
        $basename = $info['basename'];
        $dirname = $info['dirname'];

        foreach ($this->sizes as $prefix => $paths) {
            if (strpos($basename, $prefix) !== 0) {
                continue;
            }

            foreach ($paths as $path => $transform) {
                $needle = $path === '' ? '' : substr($dirname, -strlen($path));

                if ($path === $needle) {
                    return [Utils\Helpers::joinPath($dirname, substr($basename, strlen($prefix))), $transform];
                }
            }
        }

        return false;
    }
957858
private function sanitizeRootPath(string $path): string
    {
        if (!empty($path) && false !== $real = realpath($path)) {
            return $real;
        }

        throw new InvalidArgumentException(sprintf('Root image path not resolvable "%s"', $path));
    }
1342527
public function getPath(string $path): Path
    {
        if (!$this->hasPath($path)) {
            throw new \InvalidArgumentException(
                "Path '$path' does not exist (have " . implode(', ', array_keys($this->paths)) . ')'
            );
        }

        return $this->paths[$path];
    }
1155469
public function basePath($path = null)
    {
        if (isset($this->basePath)) {
            return $this->basePath.($path ? '/'.$path : $path);
        }

        if ($this->runningInConsole()) {
            $this->basePath = getcwd();
        } else {
            $this->basePath = realpath(getcwd().'/../');
        }

        return $this->basePath($path);
    }
1032454
protected function _getRalativePath($path)
    {
        if ($path) {
            $rootPath = str_replace(array('/', '\\'), '/', self::$_config['root']);

            $path = str_replace(array('/', '\\'), '/', $path);
            $path = str_replace($rootPath, '/', $path);
            $path = str_replace('//', '/', $path);
            $path = trim($path, '/');
        }
        return $path;
    }
497021
public static function getType($path)
    {
        if (!is_file($path)) {
            throw new \InvalidArgumentException(sprintf('invalid filename or path "%s"', $path));
        }

        $info = (new \finfo(FILEINFO_MIME))->file($path);

        return substr($info, 0, strpos($info, ';'));
    }
11365
protected function parsePath(string $path): array
    {
        $parts = explode(DIRECTORY_SEPARATOR, $path);

        $file = array_pop($parts);

        return [
            'root' => implode(DIRECTORY_SEPARATOR, $parts),
            'file' => $file,
        ];
    }
1042301
private function convertPath($path)
    {
        if ($path === null) {
            return null;
        }

        return (new Path($path, $this->baseDir))->toString();
    }
1044459
protected function loadFile($path)
    {
        if (pathinfo($path, PATHINFO_EXTENSION) !== 'php') {
            throw new \InvalidArgumentException('Can only parse files with ".php" extensions');
        }
        if (!file_exists($path)) {
            throw new \InvalidArgumentException(sprintf('Failed to find \'%s\' file.', $path));
        }

        return file_get_contents($path);
    }
351071
public function resourcePath($path = '')
    {
        if ($this->resourcePath) {
            return $this->resourcePath.($path ? '/'.$path : $path);
        }

        return $this->basePath('resources'.($path ? '/'.$path : $path));
    }
603177
protected function splitPath($path)
    {
        $chunks = array_map(
            [$this, 'unescape'],
            preg_split('#(?<!\\\)\/#', ltrim($path, '/'))
        );

        if (empty($chunks) || (array_filter($chunks) !== $chunks)) {
            throw new \InvalidArgumentException('Invalid path provided:' . $path);
        }

        return $chunks;
    }
1160430
private function parsePath($path)
    {
        if (empty($path)) {
            $path = Map::DEFAULT_URL_DELIMITER;
        }

        // get the clean path
        return $this->urlParser->parse($path);
    }
965962
public function setPath($path)
    {
        if (preg_match(self::PATTERN_MATCH_PATH, $path) !== 1) {
            throw new \InvalidArgumentException('"' . $path . '" is not valid path as part of a URI.', 1184071242);
        }

        $this->path = $path;
    }
800010
protected function parsePath($path)
    {
        $path = ltrim($path, '/');
        foreach ($this->combinedResources as $resource) {
            if (strpos($path, $resource) !== false) {
                list($part1, $part2) = explode($resource, $path, 2);
                $parts = array_merge(explode('/', $part1), array($resource), explode('/', $part2));
                return array_values(array_filter($parts));
            }
        }
        return explode('/', $path);
    }
279738
private function normalizePath($path)
    {
        if (!is_string($path) && !method_exists($path, '__toString')) {
            throw new InvalidArgumentException('Uri path must be a string');
        }

        $path = $this->urlEncode($path);

        if (empty($path)) {
            return '';
        }

        if ($path[0] !== '/') {
            return $path;
        }

        // Ensure only one leading slash
        return '/' . ltrim($path, '/');
    }
500963
public function withPath($path): UriInterface
   {
       if (!is_string($path)
        || !($parsedPath = $this->parsePath($path))) {
           throw new InvalidArgumentException(
               "Can't get with path: invalid expression");
       }
       return $this->with("path", $parsedPath);
   }