diff --git a/src/Model/Catalog.php b/src/Model/Catalog.php new file mode 100644 index 00000000..f9c5ce67 --- /dev/null +++ b/src/Model/Catalog.php @@ -0,0 +1,37 @@ +data = $data; + } + + /** + * @inheritdoc + */ + public static function wrapCollection(array $data, $baseUrl, ClientInterface $client) + { + $data = isset($data['info']) ? $data['info'] : []; + + return parent::wrapCollection($data, $baseUrl, $client); + } +} diff --git a/src/Model/Environment.php b/src/Model/Environment.php index 7bd5277e..ee29c9b0 100644 --- a/src/Model/Environment.php +++ b/src/Model/Environment.php @@ -3,6 +3,7 @@ namespace Platformsh\Client\Model; use Cocur\Slugify\Slugify; +use GuzzleHttp\ClientInterface; use Platformsh\Client\Exception\EnvironmentStateException; use Platformsh\Client\Exception\OperationUnavailableException; use Platformsh\Client\Model\Backups\BackupConfig; @@ -368,6 +369,21 @@ public function synchronize($data = false, $code = false, $rebase = false) return $this->runLongOperation('synchronize', 'post', $body); } + /** + * {@inheritDoc} + */ + public static function wrapCollection(array $data, $baseUrl, ClientInterface $client) + { + // The environments collection contains full information about each + // environment, so set $full to true when initializing. + $resources = []; + foreach ($data as $item) { + $resources[] = new static($item, $baseUrl, $client, true); + } + + return $resources; + } + /** * Create a backup of the environment. * diff --git a/src/Model/SetupOptions.php b/src/Model/SetupOptions.php new file mode 100644 index 00000000..9da17820 --- /dev/null +++ b/src/Model/SetupOptions.php @@ -0,0 +1,46 @@ +createRequest('post', $url, ['json' => $body]); + $response = $client->send($request); + $body = $response->getBody()->getContents(); + $data = []; + if ($body) { + $response->getBody()->seek(0); + $data = $response->json(); + } + return $data; + } catch (BadResponseException $e) { + throw $e; + } + } +} diff --git a/src/Model/Subscription.php b/src/Model/Subscription.php index 47f0971e..071eca58 100644 --- a/src/Model/Subscription.php +++ b/src/Model/Subscription.php @@ -16,6 +16,7 @@ * @property-read int $user_licenses Number of users. * @property-read string $project_id * @property-read string $project_title + * @property-read string $project_options * @property-read string $project_region * @property-read string $project_region_label * @property-read string $project_ui diff --git a/src/PlatformClient.php b/src/PlatformClient.php index 94dac42b..5939d496 100644 --- a/src/PlatformClient.php +++ b/src/PlatformClient.php @@ -9,7 +9,9 @@ use Platformsh\Client\Model\Plan; use Platformsh\Client\Model\Project; use Platformsh\Client\Model\Region; +use Platformsh\Client\Model\Catalog; use Platformsh\Client\Model\Result; +use Platformsh\Client\Model\SetupOptions; use Platformsh\Client\Model\SshKey; use Platformsh\Client\Model\Subscription; @@ -232,7 +234,9 @@ protected function cleanRequest(array $request) * @param int $storage The storage of each environment, in MiB. * @param int $environments The number of available environments. * @param array $activationCallback An activation callback for the subscription. + * @param string $catalog The catalog item url. See getCatalog(). * + * @see PlatformClient::getCatalog() * @see PlatformClient::getRegions() * @see Subscription::wait() * @@ -241,8 +245,9 @@ protected function cleanRequest(array $request) * similar code to wait for the subscription's project to be provisioned * and activated. */ - public function createSubscription($region, $plan = 'development', $title = null, $storage = null, $environments = null, array $activationCallback = null) + public function createSubscription($region, $plan = 'development', $title = null, $storage = null, $environments = null, array $activationCallback = null, $catalog = null) { + $url = $this->accountsEndpoint . 'subscriptions'; $values = $this->cleanRequest([ 'project_region' => $region, @@ -251,8 +256,9 @@ public function createSubscription($region, $plan = 'development', $title = null 'storage' => $storage, 'environments' => $environments, 'activation_callback' => $activationCallback, + 'options_url' => $catalog, ]); - + return Subscription::create($values, $url, $this->connector->getClient()); } @@ -333,4 +339,40 @@ public function getRegions() { return Region::getCollection($this->accountsEndpoint . 'regions', 0, [], $this->getConnector()->getClient()); } + + /** + * Get the project options catalog. + * + * @return Catalog[] + */ + public function getCatalog() + { + return Catalog::create([], $this->accountsEndpoint . 'setup/catalog', $this->getConnector()->getClient()); + } + + /** + * Get the setup options file for a user. + * + * @param string $vendor The query string containing the vendor machine name. + * @param string $plan The machine name of the plan which has been selected during the project setup process. + * @param string $options_url The URL of a project options file which has been selected as a setup template. + * @param string $username The name of the account for which the project is to be created. + * @param string $organization The name of the organization for which the project is to be created. + * + * + * @return SetupOptions[] + */ + public function getSetupOptions($vendor = NULL, $plan = NULL, $options_url = NULL, $username = NULL, $organization = NULL) + { + $url = $this->accountsEndpoint . 'setup/options'; + $options = $this->cleanRequest([ + 'vendor' => $vendor, + 'plan' => $plan, + 'options_url' => $options_url, + 'username' => $username, + 'organization' => $organization + ]); + + return SetupOptions::getList($options, $url, $this->connector->getClient()); + } }