1313class Client
1414{
1515 private $ browser ;
16+ private $ url ;
1617 private $ parser ;
1718
18- public function __construct (Browser $ browser , ResponseParser $ parser = null )
19+ public function __construct (Browser $ browser , $ url , ResponseParser $ parser = null )
1920 {
2021 if ($ parser === null ) {
2122 $ parser = new ResponseParser ();
2223 }
2324
2425 $ this ->browser = $ browser ;
26+ $ this ->url = $ url ;
2527 $ this ->parser = $ parser ;
2628 }
2729
2830 public function ping ()
2931 {
30- return $ this ->browser ->get ('/_ping ' )->then (array ($ this ->parser , 'expectPlain ' ));
32+ return $ this ->browser ->get ($ this -> url ( '/_ping ' ) )->then (array ($ this ->parser , 'expectPlain ' ));
3133 }
3234
3335 public function info ()
3436 {
35- return $ this ->browser ->get ('/info ' )->then (array ($ this ->parser , 'expectJson ' ));
37+ return $ this ->browser ->get ($ this -> url ( '/info ' ) )->then (array ($ this ->parser , 'expectJson ' ));
3638 }
3739
3840 public function version ()
3941 {
40- return $ this ->browser ->get ('/version ' )->then (array ($ this ->parser , 'expectJson ' ));
42+ return $ this ->browser ->get ($ this -> url ( '/version ' ) )->then (array ($ this ->parser , 'expectJson ' ));
4143 }
4244
4345 public function containerList ($ all = false , $ size = false )
4446 {
45- return $ this ->browser ->get ('/containers/json?all= ' . $ all . '&size= ' . $ size )->then (array ($ this ->parser , 'expectJson ' ));
47+ return $ this ->browser ->get ($ this -> url ( '/containers/json?all= ' . $ all . '&size= ' . $ size) )->then (array ($ this ->parser , 'expectJson ' ));
4648 }
4749
4850 public function containerInspect ($ container )
4951 {
50- return $ this ->browser ->get ('/containers/ ' . $ container . '/json ' )->then (array ($ this ->parser , 'expectJson ' ));
52+ return $ this ->browser ->get ($ this -> url ( '/containers/ ' . $ container . '/json ' ) )->then (array ($ this ->parser , 'expectJson ' ));
5153 }
5254
5355 public function containerTop ($ container )
5456 {
55- return $ this ->browser ->get ('/containers/ ' . $ container . '/top ' )->then (array ($ this ->parser , 'expectJson ' ));
57+ return $ this ->browser ->get ($ this -> url ( '/containers/ ' . $ container . '/top ' ) )->then (array ($ this ->parser , 'expectJson ' ));
5658 }
5759
5860 public function containerWait ($ container )
5961 {
60- return $ this ->browser ->post ('/containers/ ' . $ container . '/wait ' )->then (array ($ this ->parser , 'expectJson ' ));
62+ return $ this ->browser ->post ($ this -> url ( '/containers/ ' . $ container . '/wait ' ) )->then (array ($ this ->parser , 'expectJson ' ));
6163 }
6264
6365 /**
@@ -68,7 +70,7 @@ public function containerWait($container)
6870 */
6971 public function containerStop ($ container , $ t )
7072 {
71- return $ this ->browser ->post ('/containers/ ' . $ container . '/stop?t= ' . $ t )->then (array ($ this ->parser , 'expectEmpty ' ));
73+ return $ this ->browser ->post ($ this -> url ( '/containers/ ' . $ container . '/stop?t= ' . $ t) )->then (array ($ this ->parser , 'expectEmpty ' ));
7274 }
7375
7476 /**
@@ -79,22 +81,22 @@ public function containerStop($container, $t)
7981 */
8082 public function containerRestart ($ container , $ t )
8183 {
82- return $ this ->browser ->post ('/containers/ ' . $ container . '/restart?t= ' . $ t )->then (array ($ this ->parser , 'expectEmpty ' ));
84+ return $ this ->browser ->post ($ this -> url ( '/containers/ ' . $ container . '/restart?t= ' . $ t) )->then (array ($ this ->parser , 'expectEmpty ' ));
8385 }
8486
8587 public function containerKill ($ container , $ signal = null )
8688 {
87- return $ this ->browser ->post ('/containers/ ' . $ container . '/kill?signal= ' . $ signal )->then (array ($ this ->parser , 'expectEmpty ' ));
89+ return $ this ->browser ->post ($ this -> url ( '/containers/ ' . $ container . '/kill?signal= ' . $ signal) )->then (array ($ this ->parser , 'expectEmpty ' ));
8890 }
8991
9092 public function containerPause ($ container )
9193 {
92- return $ this ->browser ->post ('/containers/ ' . $ container . '/pause ' )->then (array ($ this ->parser , 'expectEmpty ' ));
94+ return $ this ->browser ->post ($ this -> url ( '/containers/ ' . $ container . '/pause ' ) )->then (array ($ this ->parser , 'expectEmpty ' ));
9395 }
9496
9597 public function containerUnpause ($ container )
9698 {
97- return $ this ->browser ->post ('/containers/ ' . $ container . '/unpause ' )->then (array ($ this ->parser , 'expectEmpty ' ));
99+ return $ this ->browser ->post ($ this -> url ( '/containers/ ' . $ container . '/unpause ' ) )->then (array ($ this ->parser , 'expectEmpty ' ));
98100 }
99101
100102 /**
@@ -106,11 +108,16 @@ public function containerUnpause($container)
106108 */
107109 public function containerDelete ($ container , $ v = false , $ force = false )
108110 {
109- return $ this ->browser ->delete ('/containers/ ' . $ container . '?v= ' . (int )$ v . '&force= ' . (int )$ force )->then (array ($ this ->parser , 'expectEmpty ' ));
111+ return $ this ->browser ->delete ($ this -> url ( '/containers/ ' . $ container . '?v= ' . (int )$ v . '&force= ' . (int )$ force) )->then (array ($ this ->parser , 'expectEmpty ' ));
110112 }
111113
112114 public function containerResize ($ container , $ w , $ h )
113115 {
114- return $ this ->browser ->get ('/containers/ ' . $ container . '/resize?w= ' . $ w . '&h= ' . $ h )->then (array ($ this ->parser , 'expectEmpty ' ));
116+ return $ this ->browser ->get ($ this ->url ('/containers/ ' . $ container . '/resize?w= ' . $ w . '&h= ' . $ h ))->then (array ($ this ->parser , 'expectEmpty ' ));
117+ }
118+
119+ private function url ($ url )
120+ {
121+ return $ this ->url . $ url ;
115122 }
116123}
0 commit comments