11<?php
22
3- /** @noinspection PhpUnusedPrivateFieldInspection */
4-
53declare (strict_types=1 );
64
75namespace Docker \Container ;
86
97use Curl \Curl ;
108use Docker \Image \Client as Image ;
11- use Error ;
129use Exception ;
1310
1411/**
1815 */
1916class Client
2017{
21- const TYPE = 'containers ' ;
18+ private const TYPE = 'containers ' ;
2219
2320 /**
2421 * @var Curl
@@ -574,17 +571,19 @@ public function setContainerName(string $container_name)
574571
575572 /**
576573 * @param array $networkingConfig
577- * <pre>
578- * [
579- * 'EndpointsConfig' => [
580- * 'test' => [
581- * 'Aliases' => [
582- * 'nginx'
583- * ]
584- * ]
585- * ]
586- * ]
587- * <pre>
574+ *
575+ * @example
576+ * <pre>
577+ * [
578+ * 'EndpointsConfig' =>
579+ * [
580+ * 'test' =>
581+ * [
582+ * 'Aliases' => [ 'nginx' ]
583+ * ]
584+ * ]
585+ * ]
586+ * <pre>
588587 *
589588 * @return Client
590589 *
@@ -1895,7 +1894,7 @@ public static function checkFilter(string $type, array $filters)
18951894
18961895 try {
18971896 $ filters_array_define = self ::$ $ filters_array_define ;
1898- } catch (Error | Exception $ e ) {
1897+ } catch (\ Throwable $ e ) {
18991898 throw new Exception ($ e ->getMessage (), 500 );
19001899 }
19011900
@@ -1964,24 +1963,18 @@ public function list(bool $all = false, int $limit = null, bool $size = false, a
19641963 $ filters_array = [];
19651964
19661965 if ($ filters ) {
1967- $ filters_array = [ ' filters ' => $ this ->checkFilter (__FUNCTION__ , $ filters )] ;
1966+ $ filters = $ this ->checkFilter (__FUNCTION__ , $ filters );
19681967 }
19691968
1970- $ data = [
1971- 'all ' => $ all ,
1972- 'limit ' => $ limit ,
1973- 'size ' => $ size ,
1974- ];
1975-
1976- $ data = array_merge ($ data , $ filters_array );
1977-
1978- $ url = self ::$ base_url .'/json? ' .http_build_query ($ data );
1969+ $ url = self ::$ base_url .'/json? ' .http_build_query (
1970+ array_merge (compact ('all ' , 'limit ' , 'size ' ), compact ('filters ' ))
1971+ );
19791972
19801973 return self ::$ curl ->get ($ url );
19811974 }
19821975
19831976 /**
1984- * @param null| string $create_raw
1977+ * @param string|null $create_raw
19851978 *
19861979 * @return $this
19871980 *
@@ -2093,7 +2086,7 @@ public function getCreateJson()
20932086 */
20942087 public function inspect (?string $ id , bool $ size = false )
20952088 {
2096- $ url = self ::$ base_url .'/ ' .($ id ?? $ this ->container_id ).'/json? ' .http_build_query ([ 'size ' => $ size ] );
2089+ $ url = self ::$ base_url .'/ ' .($ id ?? $ this ->container_id ).'/json? ' .http_build_query (compact ( 'size ' ) );
20972090
20982091 return self ::$ curl ->get ($ url );
20992092 }
@@ -2146,17 +2139,9 @@ public function logs(string $id,
21462139 bool $ timestamps = false ,
21472140 string $ tail = 'all ' )
21482141 {
2149- $ data = [
2150- 'follow ' => $ follow ,
2151- 'stdout ' => $ stdout ,
2152- 'stderr ' => $ stderr ,
2153- 'since ' => $ since ,
2154- 'until ' => $ until ,
2155- 'timestamps ' => $ timestamps ,
2156- 'tail ' => $ tail ,
2157- ];
2158-
2159- $ url = self ::$ base_url .'/ ' .($ id ?? $ this ->container_id ).'/ ' .__FUNCTION__ .'? ' .http_build_query ($ data );
2142+ $ url = self ::$ base_url .'/ ' .($ id ?? $ this ->container_id ).'/ ' .__FUNCTION__ .'? ' .http_build_query (compact (
2143+ 'follow ' , 'stdout ' , 'stderr ' , 'since ' , 'until ' , 'timestamps ' , 'tail '
2144+ ));
21602145
21612146 return self ::$ curl ->get ($ url );
21622147 }
@@ -2235,12 +2220,9 @@ public function stats(?string $id, bool $stream = false)
22352220 */
22362221 public function resize (?string $ id , int $ height , int $ width )
22372222 {
2238- $ data = [
2239- 'height ' => $ height ,
2240- 'width ' => $ width ,
2241- ];
2242-
2243- $ url = self ::$ base_url .'/ ' .($ id ?? $ this ->container_id ).'/resize? ' .http_build_query ($ data );
2223+ $ url = self ::$ base_url .'/ ' .($ id ?? $ this ->container_id ).'/resize? ' .http_build_query (compact (
2224+ 'height ' , 'width '
2225+ ));
22442226
22452227 return self ::$ curl ->post ($ url );
22462228 }
@@ -2461,24 +2443,17 @@ public function attach(?string $id,
24612443 {
24622444 (false === $ logs && false === $ stream ) or die ('Either the stream or logs parameter must be true ' );
24632445
2464- $ data = [
2465- 'detachKeys ' => $ detachKeys ,
2466- 'logs ' => $ logs ,
2467- 'stream ' => $ stream ,
2468- 'stdin ' => $ stdin ,
2469- 'stdout ' => $ stdout ,
2470- 'stderr ' => $ stderr ,
2471- ];
2472-
2473- $ url = self ::$ base_url .'/ ' .($ id ?? $ this ->container_id ).'/attach? ' .http_build_query ($ data );
2446+ $ url = self ::$ base_url .'/ ' .($ id ?? $ this ->container_id ).'/attach? ' .http_build_query (compact (
2447+ 'detachKeys ' , 'logs ' , 'stream ' , 'stdin ' , 'stdout ' , 'stderr '
2448+ ));
24742449
24752450 return self ::$ curl ->post ($ url );
24762451 }
24772452
24782453 /**
24792454 * Attach to a container via a websocket.
24802455 *
2481- * @param null| string $id
2456+ * @param string|null $id
24822457 * @param string $detachKeys
24832458 * @param bool $logs
24842459 * @param bool $stream
@@ -2500,15 +2475,8 @@ public function attachViaWebSocket(?string $id,
25002475 bool $ stdout = false ,
25012476 bool $ stderr = false )
25022477 {
2503- $ url = self ::$ base_url .'/ ' .($ id ?? $ this ->container_id ).'/attach/ws? ' .http_build_query ([
2504- 'detachKeys ' => $ detachKeys ,
2505- 'logs ' => $ logs ,
2506- 'stream ' => $ stream ,
2507- 'stdin ' => $ stdin ,
2508- 'stdout ' => $ stdout ,
2509- 'stderr ' => $ stderr ,
2510- ]
2511- );
2478+ $ url = self ::$ base_url .'/ ' .($ id ?? $ this ->container_id ).'/attach/ws? ' .http_build_query (
2479+ compact ('detachKeys ' , 'logs ' , 'stream ' , 'stdin ' , 'stdout ' , 'stderr ' ));
25122480
25132481 return self ::$ curl ->get ($ url );
25142482 }
@@ -2528,7 +2496,7 @@ public function attachViaWebSocket(?string $id,
25282496 */
25292497 public function wait (?string $ id , string $ condition = 'not - running ' )
25302498 {
2531- $ url = self ::$ base_url .'/ ' .($ id ?? $ this ->container_id ).'/wait? ' .http_build_query ([ 'condition ' => $ condition ] );
2499+ $ url = self ::$ base_url .'/ ' .($ id ?? $ this ->container_id ).'/wait? ' .http_build_query (compact ( 'condition ' ) );
25322500
25332501 return self ::$ curl ->post ($ url );
25342502 }
@@ -2545,15 +2513,11 @@ public function wait(?string $id, string $condition = 'not - running')
25452513 */
25462514 public function remove (?string $ id , bool $ v = false , bool $ force = false , bool $ link = false )
25472515 {
2548- $ data = [
2549- 'v ' => $ v ,
2550- 'force ' => $ force ,
2551- 'link ' => $ link ,
2552- ];
2553-
25542516 $ id = $ id ?? $ this ->container_id ;
25552517
2556- $ url = self ::$ base_url .'/ ' .$ id .'? ' .http_build_query ($ data );
2518+ $ url = self ::$ base_url .'/ ' .$ id .'? ' .http_build_query (compact (
2519+ 'v ' , 'force ' , 'link '
2520+ ));
25572521
25582522 $ output = self ::$ curl ->delete ($ url );
25592523
@@ -2572,7 +2536,7 @@ public function remove(?string $id, bool $v = false, bool $force = false, bool $
25722536 * A response header `X-Docker-Container-Path-Stat` is return containing a base64 - encoded JSON object with some
25732537 * filesystem header information about the path.
25742538 *
2575- * @param null| string $id
2539+ * @param string|null $id
25762540 * @param string $path
25772541 *
25782542 * @return mixed 200
@@ -2626,10 +2590,10 @@ public function extract(?string $id, string $path, bool $noOverwriteDirNonDir, s
26262590 {
26272591 $ id = $ id ?? $ this ->container_id ;
26282592
2629- $ url = self ::$ base_url .'/ ' .$ id .'/archive? ' .http_build_query ([
2630- 'path ' => $ path ,
2631- 'noOverwriteDirNonDir ' => $ noOverwriteDirNonDir ,
2632- ] );
2593+ $ url = self ::$ base_url .'/ ' .$ id .'/archive? ' .http_build_query (compact (
2594+ 'path ' ,
2595+ 'noOverwriteDirNonDir '
2596+ ) );
26332597
26342598 $ output = self ::$ curl ->put ($ url , $ request );
26352599
@@ -2659,11 +2623,9 @@ public function extract(?string $id, string $path, bool $noOverwriteDirNonDir, s
26592623 */
26602624 public function prune (array $ filters = [])
26612625 {
2662- $ filters = [
2663- 'filters ' => self ::checkFilter (__FUNCTION__ , $ filters ),
2664- ];
2626+ $ filters = self ::checkFilter (__FUNCTION__ , $ filters );
26652627
2666- $ url = self ::$ base_url .'/prune? ' .http_build_query ($ filters );
2628+ $ url = self ::$ base_url .'/prune? ' .http_build_query (compact ( ' filters ' ) );
26672629
26682630 return self ::$ curl ->post ($ url );
26692631 }
0 commit comments