88use React \Promise \PromiseInterface as Promise ;
99use Clue \React \Docker \Io \StreamingParser ;
1010use React \Stream \ReadableStreamInterface ;
11+ use Rize \UriTemplate ;
1112
1213/**
1314 * Docker Remote API client
@@ -29,6 +30,7 @@ class Client
2930 private $ browser ;
3031 private $ parser ;
3132 private $ streamingParser ;
33+ private $ uri ;
3234
3335 /**
3436 * Instantiate new Client
@@ -38,9 +40,10 @@ class Client
3840 * @param Browser $browser Browser instance to use, requires correct Sender and base URI
3941 * @param ResponseParser|null $parser (optional) ResponseParser instance to use
4042 * @param StreamingParser|null $streamingParser (optional) StreamingParser instance to use
43+ * @param UriTemplate|null $uri (optional) UriTemplate instance to use
4144 * @see Factory::createClient()
4245 */
43- public function __construct (Browser $ browser , ResponseParser $ parser = null , StreamingParser $ streamingParser = null )
46+ public function __construct (Browser $ browser , ResponseParser $ parser = null , StreamingParser $ streamingParser = null , UriTemplate $ uri = null )
4447 {
4548 if ($ parser === null ) {
4649 $ parser = new ResponseParser ();
@@ -50,9 +53,14 @@ public function __construct(Browser $browser, ResponseParser $parser = null, Str
5053 $ streamingParser = new StreamingParser ();
5154 }
5255
56+ if ($ uri === null ) {
57+ $ uri = new UriTemplate ();
58+ }
59+
5360 $ this ->browser = $ browser ;
5461 $ this ->parser = $ parser ;
5562 $ this ->streamingParser = $ streamingParser ;
63+ $ this ->uri = $ uri ;
5664 }
5765
5866 /**
@@ -63,7 +71,7 @@ public function __construct(Browser $browser, ResponseParser $parser = null, Str
6371 */
6472 public function ping ()
6573 {
66- return $ this ->browser ->get ($ this -> browser -> resolve ( '/_ping ' ) )->then (array ($ this ->parser , 'expectPlain ' ));
74+ return $ this ->browser ->get ('/_ping ' )->then (array ($ this ->parser , 'expectPlain ' ));
6775 }
6876
6977 /**
@@ -74,7 +82,7 @@ public function ping()
7482 */
7583 public function info ()
7684 {
77- return $ this ->browser ->get ($ this -> browser -> resolve ( '/info ' ) )->then (array ($ this ->parser , 'expectJson ' ));
85+ return $ this ->browser ->get ('/info ' )->then (array ($ this ->parser , 'expectJson ' ));
7886 }
7987
8088 /**
@@ -85,7 +93,7 @@ public function info()
8593 */
8694 public function version ()
8795 {
88- return $ this ->browser ->get ($ this -> browser -> resolve ( '/version ' ) )->then (array ($ this ->parser , 'expectJson ' ));
96+ return $ this ->browser ->get ('/version ' )->then (array ($ this ->parser , 'expectJson ' ));
8997 }
9098
9199 /**
@@ -99,7 +107,7 @@ public function version()
99107 public function containerList ($ all = false , $ size = false )
100108 {
101109 return $ this ->browser ->get (
102- $ this ->browser -> resolve (
110+ $ this ->uri -> expand (
103111 '/containers/json{?all,size} ' ,
104112 array (
105113 'all ' => $ this ->boolArg ($ all ),
@@ -120,7 +128,7 @@ public function containerList($all = false, $size = false)
120128 public function containerCreate ($ config , $ name = null )
121129 {
122130 return $ this ->postJson (
123- $ this ->browser -> resolve (
131+ $ this ->uri -> expand (
124132 '/containers/create{?name} ' ,
125133 array (
126134 'name ' => $ name
@@ -140,7 +148,7 @@ public function containerCreate($config, $name = null)
140148 public function containerInspect ($ container )
141149 {
142150 return $ this ->browser ->get (
143- $ this ->browser -> resolve (
151+ $ this ->uri -> expand (
144152 '/containers/{container}/json ' ,
145153 array (
146154 'container ' => $ container
@@ -160,7 +168,7 @@ public function containerInspect($container)
160168 public function containerTop ($ container , $ ps_args = null )
161169 {
162170 return $ this ->browser ->get (
163- $ this ->browser -> resolve (
171+ $ this ->uri -> expand (
164172 '/containers/{container}/top{?ps_args} ' ,
165173 array (
166174 'container ' => $ container ,
@@ -180,7 +188,7 @@ public function containerTop($container, $ps_args = null)
180188 public function containerChanges ($ container )
181189 {
182190 return $ this ->browser ->get (
183- $ this ->browser -> resolve (
191+ $ this ->uri -> expand (
184192 '/containers/{container}/changes ' ,
185193 array (
186194 'container ' => $ container
@@ -212,7 +220,7 @@ public function containerChanges($container)
212220 public function containerExport ($ container )
213221 {
214222 return $ this ->browser ->get (
215- $ this ->browser -> resolve (
223+ $ this ->uri -> expand (
216224 '/containers/{container}/export ' ,
217225 array (
218226 'container ' => $ container
@@ -247,7 +255,7 @@ public function containerExportStream($container)
247255 {
248256 return $ this ->streamingParser ->parsePlainStream (
249257 $ this ->browser ->get (
250- $ this ->browser -> resolve (
258+ $ this ->uri -> expand (
251259 '/containers/{container}/export ' ,
252260 array (
253261 'container ' => $ container
@@ -269,7 +277,7 @@ public function containerExportStream($container)
269277 public function containerResize ($ container , $ w , $ h )
270278 {
271279 return $ this ->browser ->get (
272- $ this ->browser -> resolve (
280+ $ this ->uri -> expand (
273281 '/containers/{container}/resize{?w,h} ' ,
274282 array (
275283 'container ' => $ container ,
@@ -291,7 +299,7 @@ public function containerResize($container, $w, $h)
291299 public function containerStart ($ container , $ config = array ())
292300 {
293301 return $ this ->postJson (
294- $ this ->browser -> resolve (
302+ $ this ->uri -> expand (
295303 '/containers/{container}/start ' ,
296304 array (
297305 'container ' => $ container
@@ -312,7 +320,7 @@ public function containerStart($container, $config = array())
312320 public function containerStop ($ container , $ t )
313321 {
314322 return $ this ->browser ->post (
315- $ this ->browser -> resolve (
323+ $ this ->uri -> expand (
316324 '/containers/{container}/stop{?t} ' ,
317325 array (
318326 'container ' => $ container ,
@@ -333,7 +341,7 @@ public function containerStop($container, $t)
333341 public function containerRestart ($ container , $ t )
334342 {
335343 return $ this ->browser ->post (
336- $ this ->browser -> resolve (
344+ $ this ->uri -> expand (
337345 '/containers/{container}/restart{?t} ' ,
338346 array (
339347 'container ' => $ container ,
@@ -354,7 +362,7 @@ public function containerRestart($container, $t)
354362 public function containerKill ($ container , $ signal = null )
355363 {
356364 return $ this ->browser ->post (
357- $ this ->browser -> resolve (
365+ $ this ->uri -> expand (
358366 '/containers/{container}/kill{?signal} ' ,
359367 array (
360368 'container ' => $ container ,
@@ -374,7 +382,7 @@ public function containerKill($container, $signal = null)
374382 public function containerPause ($ container )
375383 {
376384 return $ this ->browser ->post (
377- $ this ->browser -> resolve (
385+ $ this ->uri -> expand (
378386 '/containers/{container}/pause ' ,
379387 array (
380388 'container ' => $ container
@@ -393,7 +401,7 @@ public function containerPause($container)
393401 public function containerUnpause ($ container )
394402 {
395403 return $ this ->browser ->post (
396- $ this ->browser -> resolve (
404+ $ this ->uri -> expand (
397405 '/containers/{container}/unpause ' ,
398406 array (
399407 'container ' => $ container
@@ -412,7 +420,7 @@ public function containerUnpause($container)
412420 public function containerWait ($ container )
413421 {
414422 return $ this ->browser ->post (
415- $ this ->browser -> resolve (
423+ $ this ->uri -> expand (
416424 '/containers/{container}/wait ' ,
417425 array (
418426 'container ' => $ container
@@ -433,7 +441,7 @@ public function containerWait($container)
433441 public function containerRemove ($ container , $ v = false , $ force = false )
434442 {
435443 return $ this ->browser ->delete (
436- $ this ->browser -> resolve (
444+ $ this ->uri -> expand (
437445 '/containers/{container}{?v,force} ' ,
438446 array (
439447 'container ' => $ container ,
@@ -468,7 +476,7 @@ public function containerRemove($container, $v = false, $force = false)
468476 public function containerCopy ($ container , $ config )
469477 {
470478 return $ this ->postJson (
471- $ this ->browser -> resolve (
479+ $ this ->uri -> expand (
472480 '/containers/{container}/copy ' ,
473481 array (
474482 'container ' => $ container
@@ -505,7 +513,7 @@ public function containerCopyStream($container, $config)
505513 {
506514 return $ this ->streamingParser ->parsePlainStream (
507515 $ this ->postJson (
508- $ this ->browser -> resolve (
516+ $ this ->uri -> expand (
509517 '/containers/{container}/copy ' ,
510518 array (
511519 'container ' => $ container
@@ -527,7 +535,7 @@ public function containerCopyStream($container, $config)
527535 public function imageList ($ all = false )
528536 {
529537 return $ this ->browser ->get (
530- $ this ->browser -> resolve (
538+ $ this ->uri -> expand (
531539 '/images/json{?all} ' ,
532540 array (
533541 'all ' => $ this ->boolArg ($ all )
@@ -598,7 +606,7 @@ public function imageCreateStream($fromImage = null, $fromSrc = null, $repo = nu
598606 {
599607 return $ this ->streamingParser ->parseJsonStream (
600608 $ this ->browser ->post (
601- $ this ->browser -> resolve (
609+ $ this ->uri -> expand (
602610 '/images/create{?fromImage,fromSrc,repo,tag,registry} ' ,
603611 array (
604612 'fromImage ' => $ fromImage ,
@@ -623,7 +631,7 @@ public function imageCreateStream($fromImage = null, $fromSrc = null, $repo = nu
623631 public function imageInspect ($ image )
624632 {
625633 return $ this ->browser ->get (
626- $ this ->browser -> resolve (
634+ $ this ->uri -> expand (
627635 '/images/{image}/json ' ,
628636 array (
629637 'image ' => $ image
@@ -642,7 +650,7 @@ public function imageInspect($image)
642650 public function imageHistory ($ image )
643651 {
644652 return $ this ->browser ->get (
645- $ this ->browser -> resolve (
653+ $ this ->uri -> expand (
646654 '/images/{image}/history ' ,
647655 array (
648656 'image ' => $ image
@@ -708,10 +716,10 @@ public function imagePushStream($image, $tag = null, $registry = null, $registry
708716 {
709717 return $ this ->streamingParser ->parseJsonStream (
710718 $ this ->browser ->post (
711- $ this ->browser -> resolve (
712- '/images{+ registry}/{image}/push{?tag} ' ,
719+ $ this ->uri -> expand (
720+ '/images{/ registry}/{image}/push{?tag} ' ,
713721 array (
714- 'registry ' => ( $ registry === null ? '' : ( ' / ' . $ registry )) ,
722+ 'registry ' => $ registry ,
715723 'image ' => $ image ,
716724 'tag ' => $ tag
717725 )
@@ -734,7 +742,7 @@ public function imagePushStream($image, $tag = null, $registry = null, $registry
734742 public function imageTag ($ image , $ repo , $ tag = null , $ force = false )
735743 {
736744 return $ this ->browser ->post (
737- $ this ->browser -> resolve (
745+ $ this ->uri -> expand (
738746 '/images/{image}/tag{?repo,tag,force} ' ,
739747 array (
740748 'image ' => $ image ,
@@ -758,7 +766,7 @@ public function imageTag($image, $repo, $tag = null, $force = false)
758766 public function imageRemove ($ image , $ force = false , $ noprune = false )
759767 {
760768 return $ this ->browser ->delete (
761- $ this ->browser -> resolve (
769+ $ this ->uri -> expand (
762770 '/images/{image}{?force,noprune} ' ,
763771 array (
764772 'image ' => $ image ,
@@ -779,7 +787,7 @@ public function imageRemove($image, $force = false, $noprune = false)
779787 public function imageSearch ($ term )
780788 {
781789 return $ this ->browser ->get (
782- $ this ->browser -> resolve (
790+ $ this ->uri -> expand (
783791 '/images/search{?term} ' ,
784792 array (
785793 'term ' => $ term
@@ -799,7 +807,7 @@ public function imageSearch($term)
799807 public function execCreate ($ container , $ config )
800808 {
801809 return $ this ->postJson (
802- $ this ->browser -> resolve (
810+ $ this ->uri -> expand (
803811 '/containers/{container}/exec ' ,
804812 array (
805813 'container ' => $ container
@@ -823,7 +831,7 @@ public function execCreate($container, $config)
823831 public function execStart ($ exec , $ config )
824832 {
825833 return $ this ->postJson (
826- $ this ->browser -> resolve (
834+ $ this ->uri -> expand (
827835 '/exec/{exec}/start ' ,
828836 array (
829837 'exec ' => $ exec
@@ -847,7 +855,7 @@ public function execStart($exec, $config)
847855 public function execResize ($ exec , $ w , $ h )
848856 {
849857 return $ this ->browser ->get (
850- $ this ->browser -> resolve (
858+ $ this ->uri -> expand (
851859 '/exec/{exec}/resize{?w,h} ' ,
852860 array (
853861 'exec ' => $ exec ,
0 commit comments