Skip to content

Commit ce54a80

Browse files
committed
Update the example in the README
1 parent 281703f commit ce54a80

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,47 @@ composer require platformsh/client
2323

2424
Example:
2525
```php
26-
26+
use Platformsh\Client\Connection\Connector;
2727
use 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+
$projects = $client->getMyProjects();
46+
$project = $client->getProject('my_project_id');
4047
if ($project) {
4148
// Get the default (production) environment.
4249
$environment = $project->getEnvironment($project->default_branch);
4350

44-
// Create a new branch.
45-
$activity = $environment->branch('Sprint 1', 'sprint-1');
46-
47-
// Wait for the activity to complete.
48-
$activity->wait();
51+
// Create a new environment.
52+
$result = $environment->runOperation('branch', body: ['name' => 'sprint-1', 'title' => 'Sprint 1']);
53+
54+
// Wait for the operation to complete.
55+
$activities = $result->getActivities();
56+
while (count($activities) > 0) {
57+
foreach ($activities as $key => $activity) {
58+
if ($activity->isComplete() || $activity->state === \Platformsh\Client\Model\Activity::STATE_CANCELLED) {
59+
unset($activities[$key]);
60+
} else {
61+
echo "Waiting for the activity: {$activity->getDescription()}\n";
62+
$activity->wait(function () { echo '.'; });
63+
echo "\n";
64+
}
65+
}
66+
}
4967

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

0 commit comments

Comments
 (0)