|
1 | 1 | <?php declare(strict_types=1); |
| 2 | + |
2 | 3 | use ApiClients\Client\Travis\AsyncClient; |
3 | 4 | use ApiClients\Client\Travis\Resource\Async\Build; |
4 | 5 | use ApiClients\Client\Travis\Resource\Async\Job; |
5 | 6 | use ApiClients\Client\Travis\Resource\Async\Repository; |
6 | 7 | use React\EventLoop\Factory; |
| 8 | +use Rx\Observable; |
7 | 9 |
|
8 | 10 | require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php'; |
9 | 11 |
|
10 | 12 | $loop = Factory::create(); |
11 | 13 | $client = AsyncClient::create($loop); |
12 | 14 |
|
13 | | -$client->repository($argv[1] ?? 'WyriHaximus/php-travis-client')->flatMap(function (Repository $repository) { |
14 | | - echo 'Repository: ', PHP_EOL; |
15 | | - echo 'id: ' . $repository->id(), PHP_EOL; |
16 | | - echo 'slug: ' . $repository->slug(), PHP_EOL; |
17 | | - echo 'description: ' . $repository->description(), PHP_EOL; |
18 | | - echo 'Builds:', PHP_EOL; |
19 | | - //@todo the takeLast operator is isn't implemented yet in RxPHP, so we need to fake it for now |
20 | | - return $repository->builds() |
21 | | - ->toArray() |
22 | | - ->map(function ($builds) { |
23 | | - return array_pop($builds); |
24 | | - }); |
25 | | -})->flatMap(function (Build $build) use ($argv) { |
26 | | - echo "\t", 'Build', PHP_EOL; |
27 | | - echo "\t\t" . 'id: ' . $build->id(), PHP_EOL; |
28 | | - echo "\t\t" . 'commit id: ' . $build->commitId(), PHP_EOL; |
29 | | - echo "\t\t" . 'duration: ' . $build->duration(), PHP_EOL; |
| 15 | +Observable::fromPromise($client->repository($argv[1] ?? 'WyriHaximus/php-travis-client')) |
| 16 | + ->flatMap(function (Repository $repository) { |
| 17 | + echo 'Repository: ', PHP_EOL; |
| 18 | + echo 'id: ' . $repository->id(), PHP_EOL; |
| 19 | + echo 'slug: ' . $repository->slug(), PHP_EOL; |
| 20 | + echo 'description: ' . $repository->description(), PHP_EOL; |
| 21 | + echo 'Builds:', PHP_EOL; |
| 22 | + //@todo the takeLast operator is isn't implemented yet in RxPHP, so we need to fake it for now |
| 23 | + return $repository->builds() |
| 24 | + ->toArray() |
| 25 | + ->map(function ($builds) { |
| 26 | + return array_pop($builds); |
| 27 | + }); |
| 28 | + }) |
| 29 | + ->flatMap(function (Build $build) use ($argv) { |
| 30 | + echo "\t", 'Build', PHP_EOL; |
| 31 | + echo "\t\t" . 'id: ' . $build->id(), PHP_EOL; |
| 32 | + echo "\t\t" . 'commit id: ' . $build->commitId(), PHP_EOL; |
| 33 | + echo "\t\t" . 'duration: ' . $build->duration(), PHP_EOL; |
30 | 34 |
|
31 | | - return $build->job($argv[2] ?? 128670080); |
32 | | -})->subscribeCallback(function (Job $job) { |
33 | | - echo "\t\t" . 'Job', PHP_EOL; |
34 | | - echo "\t\t\t" . 'id: ' . $job->id(), PHP_EOL; |
35 | | - echo "\t\t\t" . 'number: ' . $job->number(), PHP_EOL; |
36 | | - echo "\t\t\t" . 'state: ' . $job->state(), PHP_EOL; |
37 | | -}); |
| 35 | + return $build->job($argv[2] ?? 128670080); |
| 36 | + }) |
| 37 | + ->subscribe(function (Job $job) { |
| 38 | + echo "\t\t" . 'Job', PHP_EOL; |
| 39 | + echo "\t\t\t" . 'id: ' . $job->id(), PHP_EOL; |
| 40 | + echo "\t\t\t" . 'number: ' . $job->number(), PHP_EOL; |
| 41 | + echo "\t\t\t" . 'state: ' . $job->state(), PHP_EOL; |
| 42 | + }); |
38 | 43 |
|
39 | 44 | $loop->run(); |
0 commit comments