Platformsh\Cli\Api::getProject PHP Method

getProject() public method

Return the user's project with the given ID.
public getProject ( string $id, string | null $host = null, boolean | null $refresh = null ) : Platformsh\Client\Model\Project | false
$id string The project ID.
$host string | null The project's hostname.
$refresh boolean | null Whether to bypass the cache.
return Platformsh\Client\Model\Project | false
    public function getProject($id, $host = null, $refresh = null)
    {
        // Find the project in the user's main project list. This uses a
        // separate cache.
        $projects = $this->getProjects($refresh);
        if (isset($projects[$id])) {
            return $projects[$id];
        }
        // Find the project directly.
        $cacheKey = sprintf('%s:project:%s:%s', self::$sessionId, $id, $host);
        $cached = self::$cache->fetch($cacheKey);
        if ($refresh || !$cached) {
            $scheme = 'https';
            if ($host !== null && ($pos = strpos($host, '//')) !== false) {
                $scheme = parse_url($host, PHP_URL_SCHEME);
                $host = substr($host, $pos + 2);
            }
            $project = $this->getClient()->getProject($id, $host, $scheme !== 'http');
            if ($project) {
                $toCache = $project->getData();
                $toCache['_endpoint'] = $project->getUri(true);
                self::$cache->save($cacheKey, $toCache, $this->config->get('api.projects_ttl'));
            }
        } else {
            $guzzleClient = $this->getClient()->getConnector()->getClient();
            $baseUrl = $cached['_endpoint'];
            unset($cached['_endpoint']);
            $project = new Project($cached, $baseUrl, $guzzleClient);
        }
        return $project;
    }