Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/Model/Catalog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Platformsh\Client\Model;

use GuzzleHttp\ClientInterface;

/**
* Represents a Platform.sh catalog.
*
* @property-read int $id
* @property-read string $label
* @property-read bool $available
* @property-read bool $private
* @property-read string $zone
* @property-read string $endpoint
*/
class Catalog extends Resource
{
/**
* @inheritdoc
*/
protected function setData(array $data)
{
$data = isset($data['info']) ? $data['info'] : $data;
$this->data = $data;
}

/**
* @inheritdoc
*/
public static function wrapCollection(array $data, $baseUrl, ClientInterface $client)
{
$data = isset($data['info']) ? $data['info'] : [];

return parent::wrapCollection($data, $baseUrl, $client);
}
}
1 change: 1 addition & 0 deletions src/Model/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions src/PlatformClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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\SshKey;
use Platformsh\Client\Model\Subscription;
Expand Down Expand Up @@ -226,13 +227,15 @@ protected function cleanRequest(array $request)
/**
* Create a new Platform.sh subscription.
*
* @param string $catalog The catalog item url. See getCatalog().
* @param string $region The region ID. See getRegions().
* @param string $plan The plan. See Subscription::$availablePlans.
* @param string $title The project title.
* @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.
*
* @see PlatformClient::getCatalog()
* @see PlatformClient::getRegions()
* @see Subscription::wait()
*
Expand All @@ -241,18 +244,20 @@ 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($catalog, $region, $plan = 'development', $title = null, $storage = null, $environments = null, array $activationCallback = null)
{

$url = $this->accountsEndpoint . 'subscriptions';
$values = $this->cleanRequest([
'project_region' => $region,
'plan' => $plan,
'project_title' => $title,
'storage' => $storage,
'environments' => $environments,
'options_url' => $catalog,
'activation_callback' => $activationCallback,
]);

return Subscription::create($values, $url, $this->connector->getClient());
}

Expand Down Expand Up @@ -333,4 +338,14 @@ 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());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty much the same objections as #39 - the catalog isn't a thing that lists items on GET /catalog, lets me GET a consitutuent item in GET/catalog/:id, etc, DELETE/PUT/PATCH to modify, POST to add to the list, etc, it's not a RESTful resource, so reusing the Resource model here is at least a bit awkward.

}
}