Skip to content

Commit 1166aa4

Browse files
committed
Add execCreate() params instead of config object
1 parent 277ca42 commit 1166aa4

6 files changed

Lines changed: 21 additions & 27 deletions

File tree

examples/benchmark-exec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
$factory = new Factory($loop);
2424
$client = $factory->createClient();
2525

26-
$client->execCreate($container, array('Cmd' => $cmd, 'AttachStdout' => true, 'AttachStderr' => true))->then(function ($info) use ($client) {
26+
$client->execCreate($container, $cmd)->then(function ($info) use ($client) {
2727
$stream = $client->execStartStream($info['Id'], true);
2828

2929
$start = microtime(true);

examples/exec-inspect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
$factory = new Factory($loop);
2424
$client = $factory->createClient();
2525

26-
$client->execCreate($container, array('Cmd' => $cmd, 'AttachStdout' => true, 'AttachStderr' => true, 'Tty' => true))->then(function ($info) use ($client) {
26+
$client->execCreate($container, $cmd, true)->then(function ($info) use ($client) {
2727
echo 'Created with info: ' . json_encode($info) . PHP_EOL;
2828

2929
return $client->execInspect($info['Id']);

examples/exec-stream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
$out = new Stream(STDOUT, $loop);
2828
$out->pause();
2929

30-
$client->execCreate($container, array('Cmd' => $cmd, 'AttachStdout' => true, 'AttachStderr' => true, 'Tty' => true))->then(function ($info) use ($client, $out) {
30+
$client->execCreate($container, $cmd, true)->then(function ($info) use ($client, $out) {
3131
$stream = $client->execStartStream($info['Id'], true);
3232
$stream->pipe($out);
3333

src/Client.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -882,12 +882,16 @@ public function imageSearch($term)
882882
/**
883883
* Sets up an exec instance in a running container id
884884
*
885-
* @param string $container container ID
886-
* @param array $config `array('Cmd' => 'date')` (see link)
885+
* @param string $container container ID
886+
* @param string $cmd Command to run specified as an array of strings
887+
* @param boolean $tty TTY mode
888+
* @param boolean $stdin attaches to STDIN of the exec command
889+
* @param boolean $stdout attaches to STDOUT of the exec command
890+
* @param boolean $stderr attaches to STDERR of the exec command
887891
* @return PromiseInterface Promise<array> with exec ID in the form of `array("Id" => $execId)`
888892
* @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#exec-create
889893
*/
890-
public function execCreate($container, $config)
894+
public function execCreate($container, $cmd, $tty = false, $stdin = false, $stdout = true, $stderr = true)
891895
{
892896
return $this->postJson(
893897
$this->uri->expand(
@@ -896,7 +900,13 @@ public function execCreate($container, $config)
896900
'container' => $container
897901
)
898902
),
899-
$config
903+
array(
904+
'Cmd' => $cmd,
905+
'Tty' => !!$tty,
906+
'AttachStdin' => !!$stdin,
907+
'AttachStdout' => !!$stdout,
908+
'AttachStderr' => !!$stderr,
909+
)
900910
)->then(array($this->parser, 'expectJson'));
901911
}
902912

tests/ClientTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,9 @@ public function testImageSearch()
379379
public function testExecCreate()
380380
{
381381
$json = array();
382-
$config = array();
383382
$this->expectRequestFlow('post', '/containers/123/exec', $this->createResponseJson($json), 'expectJson');
384383

385-
$this->expectPromiseResolveWith($json, $this->client->execCreate(123, $config));
384+
$this->expectPromiseResolveWith($json, $this->client->execCreate(123, array('env')));
386385
}
387386

388387
public function testExecDetached()

tests/FunctionalClientTest.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,7 @@ public function testStartRunning()
104104
*/
105105
public function testExecCreateWhileRunning($container)
106106
{
107-
$promise = $this->client->execCreate($container, array(
108-
'Cmd' => array('echo', '-n', 'hello', 'world'),
109-
'AttachStdout' => true,
110-
'AttachStderr' => true,
111-
'Tty' => true
112-
));
107+
$promise = $this->client->execCreate($container, array('echo', '-n', 'hello', 'world'));
113108
$exec = Block\await($promise, $this->loop);
114109

115110
$this->assertTrue(is_array($exec));
@@ -164,12 +159,7 @@ public function testExecInspectAfterRunning($exec)
164159
*/
165160
public function testExecStreamEmptyOutputWhileRunning($container)
166161
{
167-
$promise = $this->client->execCreate($container, array(
168-
'Cmd' => array('true'),
169-
'AttachStdout' => true,
170-
'AttachStderr' => true,
171-
'Tty' => true
172-
));
162+
$promise = $this->client->execCreate($container, array('true'));
173163
$exec = Block\await($promise, $this->loop);
174164

175165
$this->assertTrue(is_array($exec));
@@ -189,12 +179,7 @@ public function testExecStreamEmptyOutputWhileRunning($container)
189179
*/
190180
public function testExecDetachedWhileRunning($container)
191181
{
192-
$promise = $this->client->execCreate($container, array(
193-
'Cmd' => array('sleep', '10'),
194-
'AttachStdout' => true,
195-
'AttachStderr' => true,
196-
'Tty' => true
197-
));
182+
$promise = $this->client->execCreate($container, array('sleep', '10'));
198183
$exec = Block\await($promise, $this->loop);
199184

200185
$this->assertTrue(is_array($exec));

0 commit comments

Comments
 (0)