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;
}