/**
  * Output a clear explanation for domains API errors.
  *
  * @param ClientException $e
  * @param Project         $project
  *
  * @throws ClientException If it can't be explained.
  */
 protected function handleApiException(ClientException $e, Project $project)
 {
     $response = $e->getResponse();
     if ($response !== null && $response->getStatusCode() === 403) {
         $project->ensureFull();
         $data = $project->getData();
         if (!$project->hasLink('#manage-domains') && !empty($data['subscription']['plan']) && $data['subscription']['plan'] === 'development') {
             $this->stdErr->writeln('This project is on a Development plan. Upgrade the plan to add domains.');
         }
     } else {
         throw $e;
     }
 }
Example #2
0
 /**
  * Return the user's environments.
  *
  * @param Project   $project The project.
  * @param bool|null $refresh Whether to refresh the list.
  * @param bool      $events  Whether to update Drush aliases if the list changes.
  *
  * @return Environment[] The user's environments.
  */
 public function getEnvironments(Project $project, $refresh = null, $events = true)
 {
     $projectId = $project->getProperty('id');
     static $staticEnvironmentsCache;
     if (!$refresh && isset($staticEnvironmentsCache[$projectId])) {
         return $staticEnvironmentsCache[$projectId];
     }
     $cacheKey = 'environments:' . $projectId;
     $cached = self::$cache->fetch($cacheKey);
     if ($refresh === false && !$cached) {
         return [];
     } elseif ($refresh || !$cached) {
         $environments = [];
         $toCache = [];
         foreach ($project->getEnvironments() as $environment) {
             $environments[$environment->id] = $environment;
             $toCache[$environment->id] = $environment->getData();
         }
         // Dispatch an event if the list of environments has changed.
         if (isset($this->dispatcher) && $events && (!$cached || array_diff_key($environments, $cached))) {
             $this->dispatcher->dispatch('environments_changed', new EnvironmentsChangedEvent($project, $environments));
         }
         self::$cache->save($cacheKey, $toCache, $this->config->get('api.environments_ttl'));
     } else {
         $environments = [];
         $endpoint = $project->hasLink('self') ? $project->getLink('self', true) : $project->getProperty('endpoint');
         $guzzleClient = $this->getClient()->getConnector()->getClient();
         foreach ((array) $cached as $id => $data) {
             $environments[$id] = new Environment($data, $endpoint, $guzzleClient, true);
         }
     }
     $staticEnvironmentsCache[$projectId] = $environments;
     return $environments;
 }