@@ -23,29 +23,46 @@ composer require platformsh/client
2323
2424Example:
2525``` php
26-
26+ use Platformsh\Client\Connection\Connector;
2727use Platformsh\Client\PlatformClient;
2828
29+ // Set up configuration.
30+ $connector = new Connector([
31+ 'api_url' => 'https://api.platform.sh',
32+ 'accounts' => 'https://api.platform.sh/',
33+ 'centralized_permissions_enabled' => true,
34+ ]);
35+
2936// Initialize the client.
3037$client = new PlatformClient();
3138
3239// Set the API token to use.
3340//
3441// N.B. you must keep your API token(s) safe!
35- $client->getConnector()->setApiToken($myToken , 'exchange');
42+ $client->getConnector()->setApiToken('test' , 'exchange');
3643
37- // Get the user's first project.
38- $projects = $client->getProjects();
39- $project = reset($projects);
44+ // Get a project.
45+ $project = $client->getProject('my_project_id');
4046if ($project) {
4147 // Get the default (production) environment.
4248 $environment = $project->getEnvironment($project->default_branch);
4349
44- // Create a new branch.
45- $activity = $environment->branch('Sprint 1', 'sprint-1');
46-
47- // Wait for the activity to complete.
48- $activity->wait();
50+ // Create a new environment.
51+ $result = $environment->runOperation('branch', body: ['name' => 'sprint-1', 'title' => 'Sprint 1']);
52+
53+ // Wait for the operation to complete.
54+ $activities = $result->getActivities();
55+ while (count($activities) > 0) {
56+ foreach ($activities as $key => $activity) {
57+ if ($activity->isComplete() || $activity->state === \Platformsh\Client\Model\Activity::STATE_CANCELLED) {
58+ unset($activities[$key]);
59+ } else {
60+ echo "Waiting for the activity: {$activity->getDescription()}\n";
61+ $activity->wait(function () { echo '.'; });
62+ echo "\n";
63+ }
64+ }
65+ }
4966
5067 // Get the new branch.
5168 $sprint1 = $project->getEnvironment('sprint-1');
0 commit comments