Ejemplo n.º 1
0
 /**
  * Return the user's environments.
  *
  * @param Project $project       The project.
  * @param bool    $refresh       Whether to refresh the list.
  * @param bool    $updateAliases Whether to update Drush aliases if the list changes.
  *
  * @return Environment[] The user's environments.
  */
 public function getEnvironments(Project $project = null, $refresh = false, $updateAliases = true)
 {
     $project = $project ?: $this->getSelectedProject();
     $projectId = $project->getProperty('id');
     $this->loadCache();
     $cached = !empty(self::$cache['environments'][$projectId]);
     $stale = isset(self::$cache['environmentsRefreshed'][$projectId]) && time() - self::$cache['environmentsRefreshed'][$projectId] > $this->environmentsTtl;
     if ($refresh || !$cached || $stale) {
         self::$cache['environments'][$projectId] = array();
         $environments = array();
         $toCache = array();
         foreach ($project->getEnvironments() as $environment) {
             $environments[$environment['id']] = $environment;
             $toCache[$environment['id']] = $environment->getData();
         }
         // Recreate the aliases if the list of environments has changed.
         if ($updateAliases && array_diff_key($environments, self::$cache['environments'])) {
             $this->updateDrushAliases($project, $environments);
         }
         self::$cache['environments'][$projectId] = $toCache;
         self::$cache['environmentsRefreshed'][$projectId] = time();
     } else {
         $environments = array();
         $connector = $this->getClient(false)->getConnector();
         $endpoint = $project->hasLink('self') ? $project->getLink('self', true) : $project['endpoint'];
         $client = $connector->getClient();
         foreach (self::$cache['environments'][$projectId] as $id => $data) {
             $environments[$id] = Environment::wrap($data, $endpoint, $client);
         }
     }
     return $environments;
 }
Ejemplo n.º 2
0
 /**
  * Return the user's environments.
  *
  * @param Project $project       The project.
  * @param bool    $refresh       Whether to refresh the list.
  * @param bool    $updateAliases Whether to update Drush aliases if the list changes.
  *
  * @return Environment[] The user's environments.
  */
 public function getEnvironments(Project $project = null, $refresh = false, $updateAliases = true)
 {
     $project = $project ?: $this->getSelectedProject();
     $projectId = $project->getProperty('id');
     $cacheKey = 'environments:' . $projectId;
     $cached = self::$cache->contains($cacheKey);
     if ($refresh || !$cached) {
         $environments = array();
         $toCache = array();
         foreach ($project->getEnvironments() as $environment) {
             $environments[$environment['id']] = $environment;
             $toCache[$environment['id']] = $environment->getData();
         }
         // Recreate the aliases if the list of environments has changed.
         if ($updateAliases && (!$cached || array_diff_key($environments, self::$cache->fetch($cacheKey)))) {
             $this->updateDrushAliases($project, $environments);
         }
         self::$cache->save($cacheKey, $toCache, $this->environmentsTtl);
     } else {
         $environments = array();
         $connector = $this->getClient(false)->getConnector();
         $endpoint = $project->hasLink('self') ? $project->getLink('self', true) : $project['endpoint'];
         $client = $connector->getClient();
         foreach ((array) self::$cache->fetch($cacheKey) as $id => $data) {
             $environments[$id] = Environment::wrap($data, $endpoint, $client);
         }
     }
     return $environments;
 }