Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Client Laravel Package

platformsh/client

PHP client library for the Platform.sh API. Authenticate with an API token, then manage projects, environments, and activities (e.g., branch operations) and create subscriptions. Used by the Platform.sh CLI; supports PHP 8.2+ in v3.

View on GitHub
Deep Wiki
Context7

Platform.sh API client

This is a PHP library for accessing the Platform.sh API.

We recommend you use the Platform.sh CLI (which uses this library) for most purposes.

Versions

  • The 3.x branch (major version 3) requires PHP 8.2 and above.
  • The 2.x branch (major version 2) requires PHP 7.2.5 and above. This branch is no longer maintained.
  • The 1.x branch (any version < 2) supports PHP 5.5.9 and above, and uses Guzzle 5. Old PHP versions are supported by the Platform.sh CLI, which is why this branch is still maintained.

Install

composer require platformsh/client

Usage

Example:

use Platformsh\Client\Connection\Connector;
use Platformsh\Client\PlatformClient;

// Set up configuration.
$connector = new Connector([
    'api_url' => 'https://api.platform.sh',
    'accounts' => 'https://api.platform.sh/',
    'centralized_permissions_enabled' => true,
]);

// 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 a project.
$project = $client->getProject('my_project_id');
if ($project) {
    // Get the default (production) environment.
    $environment = $project->getEnvironment($project->default_branch);

    // Create a new environment.
    $result = $environment->runOperation('branch', body: ['name' => 'sprint-1', 'title' => 'Sprint 1']);

    // Wait for the operation to complete.
    $activities = $result->getActivities();
    while (count($activities) > 0) {
        foreach ($activities as $key => $activity) {
            if ($activity->isComplete() || $activity->state === \Platformsh\Client\Model\Activity::STATE_CANCELLED) {
                unset($activities[$key]);
            } else {
                echo "Waiting for the activity: {$activity->getDescription()}\n";
                $activity->wait(function () { echo '.'; });
                echo "\n";
            }
        }
    }

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

Creating a project:

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";
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor