Extract the snippet path from the given path.

@param string $path

@return string

@throws \InvalidArgumentException
963516
public function extractSnippetTypeFromPath($path)
    {
        if ('/' !== substr($path, 0, 1)) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Path must be absolute, got "%s"',
                    $path
                )
            );
        }

        $snippetsPath = $this->getBaseSnippetPath() . '/';
        $newPath = PathHelper::getParentPath($path);
        $newPath = substr($newPath, strlen($snippetsPath));

        if (false === $newPath) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Cannot extract snippet template type from path "%s"',
                    $path
                )
            );
        }

        return $newPath;
    }
1252372
private function filterPath(string $path): string
    {
        if ($path == '') {
            return $path;
        }

        $result = preg_replace_callback(
            '/(?:[^'.self::UNRESERVED.self::SUB_DELIMS.':@%~\/]+|%(?![A-Za-f0-9]{2}))/',
            function (array $match) {
                return rawurlencode($match[0]);
            },
            $path
        );

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

        return '/'.ltrim($result, '/');
    }
1303535
public function get(string $path)
    {
        $explode = explode('/', $path);
        $config = $this->config;
        while ($element = array_shift($explode)) {
            if (!isset($config[$element])) {
                throw new \InvalidArgumentException(
                    sprintf("Invalid configuration path '%s'", $path)
                );
            }
            $config = $config[$element];
        }

        return $config;
    }
524729
public function relPath($path = null)
    {
        # Cleaning path
        $path = preg_replace('/^\//', '', $path);

        return str_replace(public_path(), '', $this->getCurrentPath() . '/' . $path);
    }
191844
protected function removeDotSegments($path): string
    {
        if ($path === '' || $path === '/') {
            return $path;
        }

        $results = [];
        $segments = explode('/', $path);
        $segment = null;
        foreach ($segments as $segment) {
            if ($segment === '..') {
                array_pop($results);
            } elseif ($segment !== '.') {
                $results[] = $segment;
            }
        }

        $newPath = implode('/', $results);

        if ($path[0] === '/' && (! isset($newPath[0]) || $newPath[0] !== '/')) {
            // Re-add the leading slash if necessary for cases like "/.."
            $newPath = '/' . $newPath;
        } elseif ($newPath !== '' && ($segment === '.' || $segment === '..')) {
            // Add the trailing slash if necessary
            // If newPath is not empty, then $segment must be set and is the last segment from the foreach
            $newPath .= '/';
        }

        return $newPath;
    }
1359537
public static function getPath(string $path): string {
		$e = explode("/", $path);
		unset($e[count($e) - 1]);

		return implode("/", $e);
	}
87538
static public function urlToPath($path)
    {
        $path = parse_url($path);
        return $path === null ? null : str_replace('/', DIRECTORY_SEPARATOR, $path['path']);
    }
1117525
private function getPath($path)
    {
        if ($this->basePath === '' || strpos($path, $this->basePath) === 0) {
            $path = substr($path, strlen($this->basePath)) ?: '';
        }

        return $path === '' ? '/' : $path;
    }
927834
protected function _path($path) {
		return $this->rootName.($path == $this->root ? '' : $this->separator.$this->_relpath($path));
	}
366541
public function getPathParts($path)
    {
        $path = preg_replace('/\[/', '->[', $path);
        if (preg_match('/^->/', $path)) {
            $path = substr($path, 2);
        }

        return explode('->', $path);
    }
1160430
private function parsePath($path)
    {
        if (empty($path)) {
            $path = Map::DEFAULT_URL_DELIMITER;
        }

        // get the clean path
        return $this->urlParser->parse($path);
    }
462785
protected function findBasePath(string $path): ?string
    {
        preg_match('#^.+/(vendor|spryker)/.+/src/#', $path, $matches);
        if (!$matches) {
            return null;
        }

        return rtrim($matches[0], DIRECTORY_SEPARATOR);
    }
856817
protected function parseRoutePath(string $path) : string
    {
        return preg_replace(array_keys($this->patternMatchers), array_values($this->patternMatchers), $path);
    }
908582
public function resolve($path)
    {
        if ($path[0] !== '@') {
            return DIRECTORY_SEPARATOR === '/' ? $path : strtr($path, '\\', '/');
        }

        if (strpos($path, '{') !== false && preg_match_all('#{([^\}]+)}#', $path, $matches)) {
            foreach ((array)$matches[1] as $k => $match) {
                if (is_numeric($match)) {
                    $replaced = substr(function_exists('random_bytes') ? bin2hex(random_bytes($match / 2 + 1)) : md5(uniqid(mt_rand(), true)), 0, $match);
                } else {
                    /** @noinspection UnSafeIsSetOverArrayInspection */
                    $ts = isset($ts) ? $ts : time();
                    $replaced = date($match, $ts);
                }

                $path = str_replace($matches[0][$k], $replaced, $path);
            }
        }

        if (DIRECTORY_SEPARATOR === '\\') {
            $path = strtr($path, '\\', '/');
        }

        if (($pos = strpos($path, '/')) === false) {
            if (!isset($this->_aliases[$path])) {
                throw new InvalidArgumentException(['`:alias` is not exists', 'alias' => $path]);
            }
            return $this->_aliases[$path];
        }

        $alias = substr($path, 0, $pos);

        if (!isset($this->_aliases[$alias])) {
            throw new InvalidArgumentException(['`:alias` is not exists for `:path`', 'alias' => $alias, 'path' => $path]);
        }

        return $this->_aliases[$alias] . substr($path, $pos);
    }
904030
protected function realpath(string $path): string
    {
        if ($path === '') {
            return $this->baseDir;
        }

        if ($path[0] === '/' || (!empty($path[1]) && $path[1] === ':')) {
            return $path;
        }

        return $this->baseDir . '/' . $path;
    }
1229565
protected function parsePath(string $path = null): string
    {
        if ('' === $path || null === $path) {
            return '';
        }

        $path = ltrim($path, '/');

        $path = '*' === $path ? $path : '/' . $path;

        return decode($path);
    }
1105625
protected function ensurePath($path) {
    $real_path = $this->fileSystem->realpath($path);

    if (empty($real_path)) {
      throw new \InvalidArgumentException($path . ' does not exist.');
    }
    return $real_path;
  }