@@ -93,6 +93,89 @@ public function version()
9393 return $ this ->browser ->get ('/version ' )->then (array ($ this ->parser , 'expectJson ' ));
9494 }
9595
96+ /**
97+ * Get container events from docker
98+ *
99+ * This is a JSON streaming API endpoint that resolves with an array of all
100+ * individual progress events.
101+ *
102+ * If you need to access the individual progress events as they happen, you
103+ * should consider using `eventsStream()` instead.
104+ *
105+ * Note that this method will buffer all events until the stream closes.
106+ * This means that you SHOULD pass a timestamp for `$until` so that this
107+ * method only polls the given time interval and then resolves.
108+ *
109+ * The optional `$filters` parameter can be used to only get events for
110+ * certain event types, images and/or containers etc. like this:
111+ * <code>
112+ * $filters = array(
113+ * 'image' => array('ubuntu', 'busybox'),
114+ * 'event' => array('create')
115+ * );
116+ * </code>
117+ *
118+ * @param float|null $since timestamp used for polling
119+ * @param float|null $until timestamp used for polling
120+ * @param array $filters (optional) filters to apply (requires API v1.16+ / Docker v1.4+)
121+ * @return PromiseInterface Promise<array> array of event objects
122+ * @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#monitor-dockers-events
123+ * @uses self::eventsStream()
124+ * @see self::eventsStream()
125+ */
126+ public function events ($ since = null , $ until = null , $ filters = array ())
127+ {
128+ return $ this ->streamingParser ->deferredStream (
129+ $ this ->eventsStream ($ since , $ until , $ filters ),
130+ 'progress '
131+ );
132+ }
133+
134+ /**
135+ * Get container events from docker
136+ *
137+ * This is a JSON streaming API endpoint that returns a stream instance.
138+ *
139+ * The resulting stream will emit the following events:
140+ * - progress: for *each* element in the update stream
141+ * - error: once if an error occurs, will close() stream then
142+ * - close: once the stream ends (either finished or after "error")
143+ *
144+ * Please note that the resulting stream does not emit any "data" events, so
145+ * you will not be able to pipe() its events into another `WritableStream`.
146+ *
147+ * The optional `$filters` parameter can be used to only get events for
148+ * certain event types, images and/or containers etc. like this:
149+ * <code>
150+ * $filters = array(
151+ * 'image' => array('ubuntu', 'busybox'),
152+ * 'event' => array('create')
153+ * );
154+ * </code>
155+ *
156+ * @param float|null $since timestamp used for polling
157+ * @param float|null $until timestamp used for polling
158+ * @param array $filters (optional) filters to apply (requires API v1.16+ / Docker v1.4+)
159+ * @return ReadableStreamInterface stream of event objects
160+ * @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#monitor-dockers-events
161+ * @see self::events()
162+ */
163+ public function eventsStream ($ since = null , $ until = null , $ filters = array ())
164+ {
165+ return $ this ->streamingParser ->parseJsonStream (
166+ $ this ->browser ->withOptions (array ('streaming ' => true ))->get (
167+ $ this ->uri ->expand (
168+ '/events{?since,until,filters} ' ,
169+ array (
170+ 'since ' => $ since ,
171+ 'until ' => $ until ,
172+ 'filters ' => $ filters ? json_encode ($ filters ) : null
173+ )
174+ )
175+ )
176+ );
177+ }
178+
96179 /**
97180 * List containers
98181 *
0 commit comments