diff --git a/composer.json b/composer.json index 64019814..f28b819a 100644 --- a/composer.json +++ b/composer.json @@ -13,23 +13,28 @@ "Docker\\Tests\\": "tests/" } }, + "replace": { + "docker-php/docker-php": "*" + }, "require": { "php": ">=7.1", - "docker-php/docker-php-api": "4.1.*", + "docker-php/docker-php-api": "^4.1.0", "guzzlehttp/psr7": "^1.2", - "php-http/client-common": "^1.6", - "php-http/socket-client": "^1.3", + "php-http/client-common": "^2.7", + "php-http/socket-client": "^2.1.0", "php-http/message": "^1.0", - "symfony/filesystem": "^2.3 || ^3.0 || ^4.0", - "symfony/process": "^2.3 || ^3.0 || ^4.0" + "symfony/filesystem": "^7.0", + "symfony/process": "^7.0", + "symfony/http-client": "7.0", + "psr/http-factory": "^1.0" }, "suggest": { "php-http/httplug-bundle": "For integration with Symfony", "amphp/artax": "To use the async api" }, "require-dev": { - "phpunit/phpunit": "^6.0", - "friendsofphp/php-cs-fixer": "2.8.1", + "phpunit/phpunit": "^10.0", + "friendsofphp/php-cs-fixer": "3.40.0", "amphp/artax": "^3.0", "amphp/socket": "^0.10.5" }, @@ -37,6 +42,12 @@ "amphp/socket": "<0.10.5", "amphp/artax": "<3.0" }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/nexcess/docker-php-docker-php-api" + } + ], "scripts": { "test": "vendor/bin/phpunit", "test-ci": "vendor/bin/phpunit --coverage-clover build/coverage.xml", @@ -49,5 +60,10 @@ } }, "prefer-stable": true, - "minimum-stability": "dev" + "minimum-stability": "dev", + "config": { + "allow-plugins": { + "php-http/discovery": false + } + } } diff --git a/src/Docker.php b/src/Docker.php index 591acb5f..a5f960b8 100644 --- a/src/Docker.php +++ b/src/Docker.php @@ -23,61 +23,61 @@ class Docker extends Client /** * {@inheritdoc} */ - public function containerAttach(string $id, array $queryParameters = [], string $fetch = self::FETCH_OBJECT) + public function containerAttach(string $id, array $queryParameters = [], string $fetch = self::FETCH_OBJECT, array $accept = []) { - return $this->executePsr7Endpoint(new ContainerAttach($id, $queryParameters), $fetch); + return $this->executeEndpoint(new ContainerAttach($id, $queryParameters, $accept), $fetch); } /** * {@inheritdoc} */ - public function containerAttachWebsocket(string $id, array $queryParameters = [], string $fetch = self::FETCH_OBJECT) + public function containerAttachWebsocket(string $id, array $queryParameters = [], string $fetch = self::FETCH_OBJECT, array $accept = []) { - return $this->executePsr7Endpoint(new ContainerAttachWebsocket($id, $queryParameters), $fetch); + return $this->executeEndpoint(new ContainerAttachWebsocket($id, $queryParameters, $accept), $fetch); } /** * {@inheritdoc} */ - public function containerLogs(string $id, array $queryParameters = [], string $fetch = self::FETCH_OBJECT) + public function containerLogs(string $id, array $queryParameters = [], string $fetch = self::FETCH_OBJECT, array $accept = []) { - return $this->executePsr7Endpoint(new ContainerLogs($id, $queryParameters), $fetch); + return $this->executeEndpoint(new ContainerLogs($id, $queryParameters, $accept), $fetch); } /** * {@inheritdoc} */ - public function execStart(string $id, \Docker\API\Model\ExecIdStartPostBody $execStartConfig, string $fetch = self::FETCH_OBJECT) + public function execStart(string $id, ?\Docker\API\Model\ExecIdStartPostBody $requestBody = null, string $fetch = self::FETCH_OBJECT) { - return $this->executePsr7Endpoint(new ExecStart($id, $execStartConfig), $fetch); + return $this->executeEndpoint(new ExecStart($id, $requestBody), $fetch); } /** * {@inheritdoc} */ - public function imageBuild($inputStream, array $queryParameters = [], array $headerParameters = [], string $fetch = self::FETCH_OBJECT) + public function imageBuild($requestBody = null, array $queryParameters = [], array $headerParameters = [], string $fetch = self::FETCH_OBJECT) { - return $this->executePsr7Endpoint(new ImageBuild($inputStream, $queryParameters, $headerParameters), $fetch); + return $this->executeEndpoint(new ImageBuild($requestBody, $queryParameters, $headerParameters), $fetch); } /** * {@inheritdoc} */ - public function imageCreate(string $inputImage, array $queryParameters = [], array $headerParameters = [], string $fetch = self::FETCH_OBJECT) + public function imageCreate(?string $requestBody = null, array $queryParameters = [], array $headerParameters = [], string $fetch = self::FETCH_OBJECT) { - return $this->executePsr7Endpoint(new ImageCreate($inputImage, $queryParameters, $headerParameters), $fetch); + return $this->executeEndpoint(new ImageCreate($requestBody, $queryParameters, $headerParameters), $fetch); } /** * {@inheritdoc} */ - public function imagePush(string $name, array $queryParameters = [], array $headerParameters = [], string $fetch = self::FETCH_OBJECT) + public function imagePush(string $name, array $queryParameters = [], array $headerParameters = [], string $fetch = self::FETCH_OBJECT, array $accept = []) { if (isset($headerParameters['X-Registry-Auth']) && $headerParameters['X-Registry-Auth'] instanceof AuthConfig) { $headerParameters['X-Registry-Auth'] = \base64_encode($this->serializer->serialize($headerParameters['X-Registry-Auth'], 'json')); } - return $this->executePsr7Endpoint(new ImagePush($name, $queryParameters, $headerParameters), $fetch); + return $this->executeEndpoint(new ImagePush($name, $queryParameters, $headerParameters, $accept), $fetch); } /** @@ -85,15 +85,15 @@ public function imagePush(string $name, array $queryParameters = [], array $head */ public function systemEvents(array $queryParameters = [], string $fetch = self::FETCH_OBJECT) { - return $this->executePsr7Endpoint(new SystemEvents($queryParameters), $fetch); + return $this->executeEndpoint(new SystemEvents($queryParameters), $fetch); } - public static function create($httpClient = null) + public static function create($httpClient = null, array $additionalPlugins = [], array $additionalNormalizers = []) { if (null === $httpClient) { $httpClient = DockerClientFactory::createFromEnv(); } - return parent::create($httpClient); + return parent::create($httpClient, $additionalPlugins, $additionalNormalizers); } } diff --git a/src/DockerClientFactory.php b/src/DockerClientFactory.php index 918d8724..b1022944 100644 --- a/src/DockerClientFactory.php +++ b/src/DockerClientFactory.php @@ -13,29 +13,35 @@ use Http\Client\Socket\Client as SocketHttpClient; use Http\Message\MessageFactory\GuzzleMessageFactory; +use Docker\API\Client as DockerClient; + final class DockerClientFactory { /** * ( . */ - public static function create(array $config = [], PluginClientFactory $pluginClientFactory = null): HttpClient + public static function create(array $config = [], PluginClientFactory $pluginClientFactory = null): \Http\Client\Common\PluginClient { if (!\array_key_exists('remote_socket', $config)) { $config['remote_socket'] = 'unix:///var/run/docker.sock'; } - $messageFactory = new GuzzleMessageFactory(); - $socketClient = new SocketHttpClient($messageFactory, $config); $host = \preg_match('/unix:\/\//', $config['remote_socket']) ? 'http://localhost' : $config['remote_socket']; $pluginClientFactory = $pluginClientFactory ?? new PluginClientFactory(); + $httpClient = new \Http\Client\Common\PluginClient( + \Http\Discovery\Psr18ClientDiscovery::find() + ); + + $socketClient = new SocketHttpClient($httpClient, $config); + return $pluginClientFactory->createClient($socketClient, [ new ContentLengthPlugin(), new DecoderPlugin(), - new AddHostPlugin(new Uri($host)), + new AddHostPlugin(new Uri($host)) ], [ - 'client_name' => 'docker-client', + 'client_name' => 'docker-client' ]); }