1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Docker\API\Resource; |
4
|
|
|
|
5
|
|
|
use Joli\Jane\Swagger\Client\QueryParam; |
6
|
|
|
use Joli\Jane\Swagger\Client\Resource; |
7
|
|
|
|
8
|
|
|
class ExecResource extends Resource |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Sets up an exec instance in a running container id. |
12
|
|
|
* |
13
|
|
|
* @param mixed $execConfig Exec configuration |
14
|
|
|
* @param array $parameters List of parameters |
15
|
|
|
* @param string $fetch Fetch mode (object or response) |
16
|
|
|
* |
17
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
18
|
|
|
*/ |
19
|
|
|
public function create($execConfig, $parameters = [], $fetch = self::FETCH_OBJECT) |
20
|
|
|
{ |
21
|
|
|
$queryParam = new QueryParam(); |
22
|
|
|
$url = sprintf('/v1.21/containers/{id}/exec?%s', $queryParam->buildQueryString($parameters)); |
23
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), $execConfig); |
24
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
25
|
|
|
$response = $this->httpClient->sendRequest($request); |
26
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
27
|
|
|
return $response; |
28
|
|
|
} |
29
|
|
|
if ('201' == $response->getStatusCode()) { |
30
|
|
|
return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\ExecCreateResult', 'json'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return $response; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Starts a previously set up exec instance id. If detach is true, this API returns after starting the exec command. Otherwise, this API sets up an interactive session with the exec command. |
38
|
|
|
* |
39
|
|
|
* @param mixed $execStartConfig Exec configuration |
40
|
|
|
* @param mixed $id Exec instance id |
41
|
|
|
* @param array $parameters List of parameters |
42
|
|
|
* @param string $fetch Fetch mode (object or response) |
43
|
|
|
* |
44
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
45
|
|
|
*/ |
46
|
|
|
public function start($execStartConfig, $id, $parameters = [], $fetch = self::FETCH_OBJECT) |
47
|
|
|
{ |
48
|
|
|
$queryParam = new QueryParam(); |
49
|
|
|
$url = sprintf('/v1.21/exec/%s/start?%s', $id, $queryParam->buildQueryString($parameters)); |
50
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), $execStartConfig); |
51
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
52
|
|
|
$response = $this->httpClient->sendRequest($request); |
53
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
54
|
|
|
return $response; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $response; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Resize the tty session used by the exec command id. |
62
|
|
|
* |
63
|
|
|
* @param mixed $id Exec instance id |
64
|
|
|
* @param array $parameters List of parameters |
65
|
|
|
* @param string $fetch Fetch mode (object or response) |
66
|
|
|
* |
67
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
public function resize($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$queryParam = new QueryParam(); |
72
|
|
|
$queryParam->setDefault('w', null); |
73
|
|
|
$url = sprintf('/v1.21/exec/%s/resize?%s', $id, $queryParam->buildQueryString($parameters)); |
74
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), null); |
75
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
76
|
|
|
$response = $this->httpClient->sendRequest($request); |
77
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
78
|
|
|
return $response; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $response; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Return low-level information about the exec command id. |
86
|
|
|
* |
87
|
|
|
* @param mixed $id Exec instance id |
88
|
|
|
* @param array $parameters List of parameters |
89
|
|
|
* @param string $fetch Fetch mode (object or response) |
90
|
|
|
* |
91
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
92
|
|
|
*/ |
93
|
|
|
public function find($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
94
|
|
|
{ |
95
|
|
|
$queryParam = new QueryParam(); |
96
|
|
|
$url = sprintf('/v1.21/exec/%s/json?%s', $id, $queryParam->buildQueryString($parameters)); |
97
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), null); |
98
|
|
|
$request = $request->withHeader('Host', 'localhost'); |
99
|
|
|
$response = $this->httpClient->sendRequest($request); |
100
|
|
|
if (self::FETCH_RESPONSE == $fetch) { |
101
|
|
|
return $response; |
102
|
|
|
} |
103
|
|
|
if ('200' == $response->getStatusCode()) { |
104
|
|
|
return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\ExecCommand', 'json'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $response; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.