/** * Get the logged-in user's projects. * * @param bool $reset * * @return Project[] */ public function getProjects($reset = false) { $data = $this->getAccountInfo($reset); $client = $this->connector->getClient(); $projects = []; foreach ($data['projects'] as $project) { // Each project has its own endpoint on a Platform.sh region. $projects[] = Project::wrap($project, $project['endpoint'], $client); } return $projects; }
/** * Return the user's projects. * * @param boolean $refresh Whether to refresh the list of projects. * * @return Project[] The user's projects. */ public function getProjects($refresh = false) { $this->loadCache(); $cached = isset(self::$cache['projects']); $stale = isset(self::$cache['projectsRefreshed']) && time() - self::$cache['projectsRefreshed'] > $this->projectsTtl; if ($refresh || !$cached || $stale) { $projects = $this->getClient()->getProjects(); foreach ($projects as $id => $project) { self::$cache['projects'][$id] = $project->getData(); self::$cache['projects'][$id]['_endpoint'] = $project->getUri(true); } self::$cache['projectsRefreshed'] = time(); } else { $projects = array(); $connector = $this->getClient(false)->getConnector(); $client = $connector->getClient(); foreach (self::$cache['projects'] as $id => $data) { $projects[$id] = Project::wrap($data, $data['_endpoint'], $client); } } return $projects; }
/** * Return the user's projects. * * @param boolean $refresh Whether to refresh the list of projects. * * @return Project[] The user's projects, keyed by project ID. */ public function getProjects($refresh = false) { $cacheKey = 'projects'; /** @var Project[] $projects */ $projects = array(); if ($refresh || !self::$cache->contains($cacheKey)) { foreach ($this->getClient()->getProjects() as $project) { $projects[$project->id] = $project; } $cachedProjects = array(); foreach ($projects as $id => $project) { $cachedProjects[$id] = $project->getData(); $cachedProjects[$id]['_endpoint'] = $project->getUri(true); $cachedProjects[$id]['git'] = $project->getGitUrl(); } self::$cache->save($cacheKey, $cachedProjects, $this->projectsTtl); } else { $connector = $this->getClient(false)->getConnector(); $client = $connector->getClient(); foreach ((array) self::$cache->fetch($cacheKey) as $id => $data) { $projects[$id] = Project::wrap($data, $data['_endpoint'], $client); } } return $projects; }