Skip to content

Commit 03a8eeb

Browse files
committed
Use compact function
1 parent e8ce27e commit 03a8eeb

11 files changed

Lines changed: 68 additions & 124 deletions

File tree

.travis.yml

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ cache:
1414
directories:
1515
- cache
1616

17-
sudo: required
18-
1917
services:
2018
- docker
2119
# - rabbitmq
@@ -31,6 +29,7 @@ php:
3129
# - 7.0
3230
# - 7.1
3331
- 7.2
32+
- 7.3
3433

3534
#
3635
# 设置数据库
@@ -69,33 +68,14 @@ before_install:
6968
- sudo curl -fsSL http://get.sensiolabs.org/sami.phar -o /usr/local/bin/sami
7069
- sudo chmod +x /usr/local/bin/sami
7170

72-
jobs:
73-
include:
74-
- stage: test
75-
install:
76-
- composer install -q
77-
# - composer update -q
78-
script:
79-
- vendor/bin/phpunit --coverage-clover=coverage.xml
80-
after_success:
81-
- bash <(curl -s https://codecov.io/bash)
82-
- sami update .sami.php
83-
# - stage: deploy
84-
# script: " if ! [ -z \"${TRAVIS_TAG}\" ];then
85-
# echo \"${TRAVIS_TAG}\" ;
86-
# docker build -t khs1994/php-fpm:swarm-7.2.0-alpine3.7-${TRAVIS_TAG} --target=php . ;
87-
# docker build -t khs1994/nginx:swarm-1.13.0-alpine-${TRAVIS_TAG} . ;
88-
# docker login -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD} ;
89-
# docker push khs1994/php-fpm:swarm-7.2.0-alpine3.7-${TRAVIS_TAG} ;
90-
# docker push khs1994/nginx:swarm-1.13.0-alpine-${TRAVIS_TAG} ;
91-
# else
92-
# echo \"NOT TAG, Don't Build\";
93-
# fi "
94-
95-
stages:
96-
- test
97-
# - name: deploy
98-
# if: tag =~ ^[0-9.]+$
71+
install:
72+
- composer install -q
73+
# - composer update -q
74+
script:
75+
- vendor/bin/phpunit --coverage-clover=coverage.xml
76+
after_success:
77+
- bash <(curl -s https://codecov.io/bash)
78+
- sami update .sami.php
9979

10080
env:
10181
global:

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
Copyright (c) 2011-2018 khs1994, https://khs1994.com <khs1994@khs1994.com>
2+
Copyright (c) 2011-2019 khs1994, https://khs1994.com <khs1994@khs1994.com>
33

44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"khs1994/curl": "~18.06.0"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit": "^7.1"
30+
"phpunit/phpunit": "^8.0"
3131
},
3232
"config": {
3333
"optimize-autoloader": true,

src/Docker/Container/Client.php

Lines changed: 44 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
<?php
22

3-
/** @noinspection PhpUnusedPrivateFieldInspection */
4-
53
declare(strict_types=1);
64

75
namespace Docker\Container;
86

97
use Curl\Curl;
108
use Docker\Image\Client as Image;
11-
use Error;
129
use Exception;
1310

1411
/**
@@ -18,7 +15,7 @@
1815
*/
1916
class 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
}

src/Docker/Docker.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
/** @noinspection PhpMissingParentConstructorInspection */
4-
53
declare(strict_types=1);
64

75
namespace Docker;
@@ -35,7 +33,7 @@
3533
*/
3634
class Docker extends ServiceContainer
3735
{
38-
const VERSION = '18.06.0';
36+
private const VERSION = '18.06.0';
3937

4038
const DOCKER_HEALTH_STARTING = 'starting';
4139

@@ -195,4 +193,9 @@ public function __call($name, $arguments)
195193
{
196194
return $this->$name;
197195
}
196+
197+
public function version()
198+
{
199+
return self::VERSION;
200+
}
198201
}

src/Docker/Image/Client.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace Docker\Image;
88

99
use Curl\Curl;
10-
use Error;
1110
use Exception;
1211

1312
/**
@@ -87,7 +86,7 @@ private function resolveFilters(string $type, array $filters)
8786

8887
try {
8988
$filters_array_defined = self::$$filters_array_defined;
90-
} catch (Error | Exception $e) {
89+
} catch (\Throwable $e) {
9190
throw new Exception($e->getMessage(), $e->getCode());
9291
}
9392

src/Docker/Network/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function list(array $filter = [])
110110
public function inspect(string $id, bool $verbose = false, string $scope = null)
111111
{
112112
if ($scope) {
113-
array_key_exists($scope, ['swarm', 'global', 'local']) or die("$scope error");
113+
\array_key_exists($scope, ['swarm', 'global', 'local']) or die("$scope error");
114114
}
115115
$data = [
116116
'verbose' => $verbose,

src/Docker/Plugin/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
*/
1414
class Client
1515
{
16-
const TYPE = 'plugins';
16+
private const TYPE = 'plugins';
1717

18-
const BASE_URL = '/'.self::TYPE;
18+
private const BASE_URL = '/'.self::TYPE;
1919

2020
private $base_url;
2121

0 commit comments

Comments
 (0)