@@ -58,14 +58,11 @@ Once [installed](#install), you can use the following code to access the
58
58
Docker API of your local docker daemon:
59
59
60
60
``` php
61
- $loop = React\EventLoop\Factory::create();
62
- $client = new Clue\React\Docker\Client($loop);
61
+ $client = new Clue\React\Docker\Client();
63
62
64
63
$client->imageSearch('clue')->then(function (array $images) {
65
64
var_dump($images);
66
65
});
67
-
68
- $loop->run();
69
66
```
70
67
71
68
See also the [ examples] ( examples ) .
@@ -75,23 +72,26 @@ See also the [examples](examples).
75
72
### Client
76
73
77
74
The ` Client ` is responsible for assembling and sending HTTP requests to the Docker Engine API.
78
- It uses an HTTP client bound to the main [ ` EventLoop ` ] ( https://github.com/reactphp/event-loop#usage )
79
- in order to handle async requests:
80
75
81
76
``` php
82
- $loop = React\EventLoop\Factory::create();
83
- $client = new Clue\React\Docker\Client($loop);
77
+ $client = new Clue\React\Docker\Client();
84
78
```
85
79
80
+ This class takes an optional ` LoopInterface|null $loop ` parameter that can be used to
81
+ pass the event loop instance to use for this object. You can use a ` null ` value
82
+ here in order to use the [ default loop] ( https://github.com/reactphp/event-loop#loop ) .
83
+ This value SHOULD NOT be given unless you're sure you want to explicitly use a
84
+ given event loop instance.
85
+
86
86
If your Docker Engine API is not accessible using the default ` unix:///var/run/docker.sock `
87
87
Unix domain socket path, you may optionally pass an explicit URL like this:
88
88
89
- ```
89
+ ``` php
90
90
// explicitly use given UNIX socket path
91
- $client = new Clue\React\Docker\Client($loop , 'unix:///var/run/docker.sock');
91
+ $client = new Clue\React\Docker\Client(null , 'unix:///var/run/docker.sock');
92
92
93
93
// or connect via TCP/IP to a remote Docker Engine API
94
- $client = new Clue\React\Docker\Client($loop , 'http://10.0.0.2:8000/');
94
+ $client = new Clue\React\Docker\Client(null , 'http://10.0.0.2:8000/');
95
95
```
96
96
97
97
#### Commands
@@ -154,13 +154,12 @@ The resulting blocking code could look something like this:
154
154
``` php
155
155
use Clue\React\Block;
156
156
157
- $loop = React\EventLoop\Factory::create();
158
- $client = new Clue\React\Docker\Client($loop);
157
+ $client = new Clue\React\Docker\Client();
159
158
160
159
$promise = $client->imageInspect('busybox');
161
160
162
161
try {
163
- $results = Block\await($promise, $loop );
162
+ $results = Block\await($promise, Loop::get() );
164
163
// resporesults successfully received
165
164
} catch (Exception $e) {
166
165
// an error occured while performing the request
@@ -175,7 +174,7 @@ $promises = array(
175
174
$client->imageInspect('ubuntu'),
176
175
);
177
176
178
- $inspections = Block\awaitAll($promises, $loop );
177
+ $inspections = Block\awaitAll($promises, Loop::get() );
179
178
```
180
179
181
180
Please refer to [ clue/reactphp-block] ( https://github.com/clue/reactphp-block#readme ) for more details.
0 commit comments