Skip to content

Commit 32cd9b1

Browse files
committed
Added missing sync examples and necesary methods to sync program resource
1 parent fcba1f7 commit 32cd9b1

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

examples/program-restart-extended.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types=1);
2+
3+
use ApiClients\Client\Supervisord\Client;
4+
use function ApiClients\Foundation\resource_pretty_print;
5+
6+
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
7+
8+
$client = Client::create(require __DIR__ . DIRECTORY_SEPARATOR . 'resolve_host.php');
9+
10+
$program = current($client->programs());
11+
resource_pretty_print($program);
12+
$program->disable();
13+
$program = $program->refresh();
14+
resource_pretty_print($program);
15+
$program->enable();
16+
$program = $program->refresh();
17+
resource_pretty_print($program);

examples/program-restart.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php declare(strict_types=1);
2+
3+
use ApiClients\Client\Supervisord\Client;
4+
use React\EventLoop\Factory;
5+
use function ApiClients\Foundation\resource_pretty_print;
6+
7+
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
8+
9+
$loop = Factory::create();
10+
$client = Client::create(require __DIR__ . DIRECTORY_SEPARATOR . 'resolve_host.php');
11+
12+
$program = current($client->programs());
13+
resource_pretty_print($program);
14+
resource_pretty_print($program->restart());

examples/programs.php

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99

1010
foreach ($client->programs() as $program) {
1111
resource_pretty_print($program);
12+
resource_pretty_print($program->refresh());
1213
}

src/Resource/Sync/Program.php

+21
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,25 @@ public function refresh(): Program
1414
return $program->refresh();
1515
}));
1616
}
17+
18+
public function enable(): bool
19+
{
20+
return $this->wait($this->handleCommand(new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this))->then(function (ProgramInterface $program) {
21+
return $program->enable();
22+
}));
23+
}
24+
25+
public function disable(): bool
26+
{
27+
return $this->wait($this->handleCommand(new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this))->then(function (ProgramInterface $program) {
28+
return $program->disable();
29+
}));
30+
}
31+
32+
public function restart(): Program
33+
{
34+
return $this->wait($this->handleCommand(new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this))->then(function (ProgramInterface $program) {
35+
return $program->restart();
36+
}));
37+
}
1738
}

0 commit comments

Comments
 (0)