Acquia\Cloud\Api\CloudApiClient::factory PHP Method

factory() public static method

public static factory ( $config = [] ) : CloudApiClient
return CloudApiClient
    public static function factory($config = array())
    {
        $required = array('base_url', 'username', 'password');
        $defaults = array('base_url' => self::BASE_URL, 'base_path' => self::BASE_PATH);
        // Instantiate the Acquia Search plugin.
        $config = Collection::fromConfig($config, $defaults, $required);
        $client = new static($config->get('base_url'), $config);
        $client->setDefaultHeaders(array('Content-Type' => 'application/json; charset=utf-8'));
        // Attach the Acquia Search plugin to the client.
        $plugin = new CloudApiAuthPlugin($config->get('username'), $config->get('password'));
        $client->addSubscriber($plugin);
        return $client;
    }

Usage Example

Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $tag = $input->getArgument('tag');
     $GitHub = $this->getGithub(FALSE);
     $is_environment_available = FALSE;
     if (!$input->getOption('pre-release')) {
         try {
             $release = $GitHub->api('repo')->releases()->showTag($this->getConfigParameter('organization'), $this->getConfigParameter('repository'), $tag);
         } catch (\Exception $e) {
             $output->writeln("<error>Tag: {$tag} does not exists.</error>");
             return 1;
         }
         // If the release is already marked "prerelease" fail.
         if (!empty($release['prerelease']) && $release['prerelease'] == 1) {
             $output->writeln("<error>Tag: {$tag} is marked as pre-release. Please certify before deploying</error>");
             return 1;
         }
     }
     $env = $input->getArgument('env');
     $tag = 'tags/' . $input->getArgument('tag');
     $acquia = $this->getConfigParameter('acquia');
     $subscription = $this->getConfigParameter('subscription');
     if (empty($acquia['username']) || empty($acquia['username']) || empty($subscription)) {
         $output->writeln("<error>You must have your acquia username/password/subscription configured in your flo config to run deploys.</error>");
         return 1;
     }
     $cloud_api = CloudApiClient::factory(array('username' => $acquia['username'], 'password' => $acquia['password']));
     $acquia_environments = $cloud_api->environments($subscription);
     foreach ($acquia_environments as $acquia_env) {
         if ($acquia_env->name() == $env) {
             $is_environment_available = TRUE;
             break;
         }
     }
     if (!$is_environment_available) {
         $output->writeln("<error>Environment: {$env} does not exists on Acquia Cloud.</error>");
         return 1;
     }
     $task = $cloud_api->pushCode($subscription, $env, $tag);
     $progress = new ProgressBar($output, 100);
     $progress->start();
     while (!$task->completed()) {
         $progress->advance();
         // Lets not kill their api.
         sleep(2);
         $task = $cloud_api->task($subscription, $task);
     }
     $progress->finish();
     if ($task->state() == 'failed') {
         $output->writeln("\n<error>Task: {$task->id()} failed.</error>");
         $output->writeln($task->logs());
         return 1;
     }
     $output->writeln("\n<info>Tag: {$tag} deployed.</info>");
     $output->writeln($task->logs());
 }
All Usage Examples Of Acquia\Cloud\Api\CloudApiClient::factory