Platformsh\Cli\Command\CommandBase::parseProjectId PHP Метод

parseProjectId() защищенный Метод

Parse the project ID and possibly other details from a provided URL.
protected parseProjectId ( string $url ) : array
$url string A web UI, API, or public URL of the project.
Результат array An array of containing at least a 'projectId'. Keys 'host', 'environmentId', and 'appId' will be either null or strings.
    protected function parseProjectId($url)
    {
        $result = ['projectId' => null, 'host' => null, 'environmentId' => null, 'appId' => null];
        // If it's a plain alphanumeric string, then it's an ID already.
        if (!preg_match('/\\W/', $url)) {
            $result['projectId'] = $url;
            return $result;
        }
        $this->debug('Parsing URL to determine project ID');
        $host = parse_url($url, PHP_URL_HOST);
        $path = parse_url($url, PHP_URL_PATH);
        if ((!$path || $path === '/') && preg_match('/\\-\\w+\\.[a-z]{2}\\.' . preg_quote(self::$config->get('detection.site_domain')) . '$/', $host)) {
            list($env_project_app, ) = explode('.', $host, 2);
            if (($doubleDashPos = strrpos($env_project_app, '--')) !== false) {
                $env_project = substr($env_project_app, 0, $doubleDashPos);
                $result['appId'] = substr($env_project_app, $doubleDashPos + 2);
            } else {
                $env_project = $env_project_app;
            }
            if (($dashPos = strrpos($env_project, '-')) !== false) {
                $result['projectId'] = substr($env_project, $dashPos + 1);
                $result['environmentId'] = substr($env_project, 0, $dashPos);
            }
        } else {
            $result['host'] = $host;
            $result['projectId'] = basename(preg_replace('#/projects(/\\w+)/?.*$#', '$1', $url));
            if (preg_match('#/environments(/[^/]+)/?.*$#', $url, $matches)) {
                $result['environmentId'] = rawurldecode(basename($matches[1]));
            }
        }
        if (empty($result['projectId']) || preg_match('/\\W/', $result['projectId'])) {
            throw new \InvalidArgumentException(sprintf('Invalid project URL: %s', $url));
        }
        return $result;
    }