Skip to content

Commit 1813c68

Browse files
authored
Merge pull request #72 from SimonFrings/docs
Use new HTTP and Socket API and improve documentation and examples
2 parents 92c7efb + e6228f1 commit 1813c68

21 files changed

+95
-125
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
/vendor
21
/composer.lock
2+
/vendor/

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ Once [installed](#install), you can use the following code to access the
5858
Docker API of your local docker daemon:
5959

6060
```php
61+
<?php
62+
63+
require __DIR__ . '/vendor/autoload.php';
64+
6165
$client = new Clue\React\Docker\Client();
6266

6367
$client->imageSearch('clue')->then(function (array $images) {
@@ -379,7 +383,7 @@ See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
379383

380384
This project aims to run on any platform and thus does not require any PHP
381385
extensions and supports running on legacy PHP 5.3 through current PHP 8+.
382-
It's *highly recommended to use PHP 7+* for this project.
386+
It's *highly recommended to use the latest supported PHP version* for this project.
383387

384388
## Tests
385389

@@ -393,7 +397,7 @@ $ composer install
393397
To run the test suite, go to the project root and run:
394398

395399
```bash
396-
$ php vendor/bin/phpunit
400+
$ vendor/bin/phpunit
397401
```
398402

399403
## License

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
"php": ">=5.3",
2121
"clue/json-stream": "^0.1",
2222
"react/event-loop": "^1.2",
23-
"react/http": "^1.4",
23+
"react/http": "^1.5",
2424
"react/promise": "^2.0 || ^1.1",
2525
"react/promise-stream": "^1.0",
26-
"react/socket": "^1.8",
26+
"react/socket": "^1.9",
2727
"react/stream": "^1.2",
2828
"rize/uri-template": "^0.3"
2929
},

examples/archive.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,22 @@
44
// how it can be passed to a TAR decoder and how we can then pipe each
55
// individual file to the console output.
66

7-
use Clue\CaretNotation\Encoder;
8-
use Clue\React\Docker\Client;
9-
use Clue\React\Tar\Decoder;
10-
use React\Stream\ReadableStreamInterface;
11-
127
require __DIR__ . '/../vendor/autoload.php';
138

149
$container = isset($argv[1]) ? $argv[1] : 'asd';
1510
$path = isset($argv[2]) ? $argv[2] : '/etc/passwd';
1611
echo 'Container "' . $container . '" dumping "' . $path . '" (pass as arguments to this example)' . PHP_EOL;
1712

18-
$client = new Client();
13+
$client = new Clue\React\Docker\Client();
1914

2015
$stream = $client->containerArchiveStream($container, $path);
2116

22-
$tar = new Decoder();
17+
$tar = new Clue\React\Tar\Decoder();
2318

2419
// use caret notation for any control characters except \t, \r and \n
25-
$caret = new Encoder("\t\r\n");
20+
$caret = new Clue\CaretNotation\Encoder("\t\r\n");
2621

27-
$tar->on('entry', function ($header, ReadableStreamInterface $file) use ($caret) {
22+
$tar->on('entry', function ($header, React\Stream\ReadableStreamInterface $file) use ($caret) {
2823
// write each entry to the console output
2924
echo '########## ' . $caret->encode($header['filename']) . ' ##########' . PHP_EOL;
3025
$file->on('data', function ($chunk) use ($caret) {

examples/attach-stream.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@
66
// $ docker run -it --rm --name=foo busybox sh
77
// $ php examples/attach-stream.php foo
88

9-
use Clue\CaretNotation\Encoder;
10-
use Clue\React\Docker\Client;
11-
129
require __DIR__ . '/../vendor/autoload.php';
1310

1411
$container = isset($argv[1]) ? $argv[1] : 'foo';
1512
echo 'Dumping output of container "' . $container . '" (pass as argument to this example)' . PHP_EOL;
1613

17-
$client = new Client();
14+
$client = new Clue\React\Docker\Client();
1815

1916
// use caret notation for any control characters except \t, \r and \n
20-
$caret = new Encoder("\t\r\n");
17+
$caret = new Clue\CaretNotation\Encoder("\t\r\n");
2118

2219
$stream = $client->containerAttachStream($container, true, true);
2320
$stream->on('data', function ($data) use ($caret) {

examples/benchmark-attach.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
// $ docker run -i --rm --log-driver=none busybox dd if=/dev/zero bs=1M count=1000 status=none | dd of=/dev/null
1212

13-
use Clue\React\Docker\Client;
1413
use React\EventLoop\Loop;
1514

1615
require __DIR__ . '/../vendor/autoload.php';
@@ -27,7 +26,7 @@
2726
$cmd = array_slice($argv, 2);
2827
}
2928

30-
$client = new Client();
29+
$client = new Clue\React\Docker\Client();
3130

3231
$client->containerCreate(array(
3332
'Image' => $image,

examples/benchmark-exec.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//
1414
// $ docker exec foo dd if=/dev/zero bs=1M count=1000 | dd of=/dev/null
1515

16-
use Clue\React\Docker\Client;
1716

1817
require __DIR__ . '/../vendor/autoload.php';
1918

@@ -29,7 +28,7 @@
2928
$cmd = array_slice($argv, 2);
3029
}
3130

32-
$client = new Client();
31+
$client = new Clue\React\Docker\Client();
3332

3433
$client->execCreate($container, $cmd)->then(function ($info) use ($client) {
3534
$stream = $client->execStartStream($info['Id'], true);

examples/events.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
// this simple example displays all docker events that happen in the next 10s.
44
// try starting / removing a container in the meantime to see some output.
55

6-
use Clue\React\Docker\Client;
76

87
require __DIR__ . '/../vendor/autoload.php';
98

10-
$client = new Client();
9+
$client = new Clue\React\Docker\Client();
1110

1211
// get a list of all events that happened up until this point
1312
// expect this list to be limited to the last 64 (or so) events

examples/exec-inspect.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
// this simple example executes a "sleep 2" within the given running container
44

5-
use Clue\React\Buzz\Message\ResponseException;
6-
use Clue\React\Docker\Client;
7-
85
require __DIR__ . '/../vendor/autoload.php';
96

107
$container = 'asd';
@@ -18,7 +15,7 @@
1815
$cmd = array_slice($argv, 2);
1916
}
2017

21-
$client = new Client();
18+
$client = new Clue\React\Docker\Client();
2219

2320
$client->execCreate($container, $cmd)->then(function ($info) use ($client) {
2421
echo 'Created with info: ' . json_encode($info) . PHP_EOL;
@@ -38,7 +35,7 @@
3835
}, function (Exception $e) {
3936
echo 'ERROR: ' . $e->getMessage() . PHP_EOL;
4037

41-
if ($e instanceof ResponseException) {
38+
if ($e instanceof React\Http\Message\ResponseException) {
4239
echo 'Response: ' . $e->getResponse()->getBody() . PHP_EOL;
4340
}
4441
});

examples/exec-stream.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
// this example executes some commands within the given running container and
44
// displays the streaming output as it happens.
55

6-
use Clue\React\Docker\Client;
76
use React\EventLoop\Loop;
8-
use React\Stream\WritableResourceStream;
97

108
require __DIR__ . '/../vendor/autoload.php';
119

@@ -24,10 +22,10 @@
2422
$cmd = array_slice($argv, 2);
2523
}
2624

27-
$client = new Client();
25+
$client = new Clue\React\Docker\Client();
2826

29-
$out = new WritableResourceStream(STDOUT);
30-
$stderr = new WritableResourceStream(STDERR);
27+
$out = new React\Stream\WritableResourceStream(STDOUT);
28+
$stderr = new React\Stream\WritableResourceStream(STDERR);
3129

3230
// unkown exit code by default
3331
$exit = 1;

0 commit comments

Comments
 (0)