platformsh/client

Platform.sh API客户端

2.6.0-beta3 2022-10-04 21:15 UTC

This package is auto-updated.

Last update: 2024-08-31 19:27:21 UTC


README

这是一个用于访问Platform.sh API的PHP库。

我们推荐您使用Platform.sh CLI(它使用此库)来完成大多数任务。

Build Status

版本

  • 2.x分支(主要版本2)需要PHP 7.2.5及以上。
  • 1.x分支(任何版本< 2)支持PHP 5.5.9及以上,并使用Guzzle 5。旧PHP版本由Platform.sh CLI支持,这也是为什么该分支仍然被维护的原因。

Build Status

安装

composer require platformsh/client

使用方法

示例

use Platformsh\Client\PlatformClient;

// Initialize the client.
$client = new PlatformClient();

// Set the API token to use.
//
// N.B. you must keep your API token(s) safe!
$client->getConnector()->setApiToken($myToken, 'exchange');

// Get the user's first project.
$projects = $client->getProjects();
$project = reset($projects);
if ($project) {
    // Get the default (production) environment.
    $environment = $project->getEnvironment($project->default_branch);

    // Create a new branch.
    $activity = $environment->branch('Sprint 1', 'sprint-1');

    // Wait for the activity to complete.
    $activity->wait();

    // Get the new branch.
    $sprint1 = $project->getEnvironment('sprint-1');
}

创建项目

use \Platformsh\Client\Model\Subscription\SubscriptionOptions;

$subscription = $client->createSubscription(SubscriptionOptions::fromArray([
    'project_region' => 'uk-1.platform.sh',
    'project_title' => 'My project',
    'plan' => 'development',
    'default_branch' => 'main',
]));

echo "Created subscription $subscription->id, waiting for it to activate...\n";

$subscription->wait();

$project = $subscription->getProject();

echo "The project is now active: $project->id\n";
echo "Git URI: " . $project->getGitUrl() . "\n";