Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge feature.php83 into master #3

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
32 changes: 24 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,41 @@
"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"
},
"conflict": {
"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",
Expand All @@ -49,5 +60,10 @@
}
},
"prefer-stable": true,
"minimum-stability": "dev"
"minimum-stability": "dev",
"config": {
"allow-plugins": {
"php-http/discovery": false
}
}
}
34 changes: 17 additions & 17 deletions src/Docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,77 +23,77 @@ 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);
}

/**
* {@inheritdoc}
*/
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);
}
}
16 changes: 11 additions & 5 deletions src/DockerClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]);
}

Expand Down