forked from plesk/docker-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocker.php
More file actions
214 lines (175 loc) · 5.27 KB
/
Copy pathDocker.php
File metadata and controls
214 lines (175 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
namespace Docker;
use Docker\API\Normalizer\NormalizerFactory;
use Docker\Manager\{ContainerManager,
ExecManager,
ImageManager,
MiscManager,
NetworkManager,
NodeManager,
ServiceManager,
SwarmManager,
TaskManager,
VolumeManager};
use GuzzleHttp\Psr7\HttpFactory;
use Http\Message\MessageFactory;
use Http\Message\MessageFactory\GuzzleMessageFactory;
use Psr\Http\Client\ClientInterface;
use Symfony\Component\Serializer\Encoder\JsonDecode;
use Symfony\Component\Serializer\Encoder\JsonEncode;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Serializer;
/**
* Docker\Docker
*/
class Docker
{
/**
* @var ClientInterface
*/
private $httpClient;
/**
* @var Serializer
*/
private $serializer;
/**
* @var MessageFactory
*/
private $messageFactory;
/**
* @var ContainerManager
*/
private $containerManager;
/**
* @var ImageManager
*/
private $imageManager;
/**
* @var MiscManager
*/
private $miscManager;
/**
* @var VolumeManager
*/
private $volumeManager;
/**
* @var NetworkManager
*/
private $networkManager;
/**
* @var NodeManager
*/
private $nodeManager;
/**
* @var ServiceManager
*/
private $serviceManager;
/**
* @var SwarmManager
*/
private $swarmManager;
/**
* @var TaskManager
*/
private $taskManager;
/**
* @var ExecManager
*/
private $execManager;
/**
* @param ClientInterface|null $httpClient Http client to use with Docker
* @param Serializer|null $serializer Deserialize docker response into php objects
* @param HttpFactory|null $messageFactory How to create docker request (in PSR7)
*/
public function __construct(ClientInterface $httpClient = null, Serializer $serializer = null, HttpFactory $messageFactory = null)
{
$this->httpClient = $httpClient ?: DockerClient::createFromEnv();
if ($serializer === null) {
$serializer = new Serializer(
NormalizerFactory::create(),
[
new JsonEncoder(
new JsonEncode(),
new JsonDecode(),
[JsonDecode::ASSOCIATIVE => false],
),
]
);
}
if ($messageFactory === null) {
$messageFactory = new GuzzleMessageFactory();
}
$this->serializer = $serializer;
$this->messageFactory = $messageFactory;
}
public function getContainerManager(): ContainerManager
{
if (null === $this->containerManager) {
$this->containerManager = new ContainerManager($this->httpClient, $this->messageFactory, $this->serializer);
}
return $this->containerManager;
}
public function getImageManager(): ImageManager
{
if (null === $this->imageManager) {
$this->imageManager = new ImageManager($this->httpClient, $this->messageFactory, $this->serializer);
}
return $this->imageManager;
}
public function getMiscManager(): MiscManager
{
if (null === $this->miscManager) {
$this->miscManager = new MiscManager($this->httpClient, $this->messageFactory, $this->serializer);
}
return $this->miscManager;
}
public function getExecManager(): ExecManager
{
if (null === $this->execManager) {
$this->execManager = new ExecManager($this->httpClient, $this->messageFactory, $this->serializer);
}
return $this->execManager;
}
public function getVolumeManager(): VolumeManager
{
if (null === $this->volumeManager) {
$this->volumeManager = new VolumeManager($this->httpClient, $this->messageFactory, $this->serializer);
}
return $this->volumeManager;
}
public function getNetworkManager(): NetworkManager
{
if (null === $this->networkManager) {
$this->networkManager = new NetworkManager($this->httpClient, $this->messageFactory, $this->serializer);
}
return $this->networkManager;
}
public function getNodeManager(): NodeManager
{
if (null === $this->nodeManager) {
$this->nodeManager = new NodeManager($this->httpClient, $this->messageFactory, $this->serializer);
}
return $this->nodeManager;
}
public function getServiceManager(): ServiceManager
{
if (null === $this->serviceManager) {
$this->serviceManager = new ServiceManager($this->httpClient, $this->messageFactory, $this->serializer);
}
return $this->serviceManager;
}
public function getSwarmManager(): SwarmManager
{
if (null === $this->swarmManager) {
$this->swarmManager = new SwarmManager($this->httpClient, $this->messageFactory, $this->serializer);
}
return $this->swarmManager;
}
public function getTaskManager(): TaskManager
{
if (null === $this->taskManager) {
$this->taskManager = new TaskManager($this->httpClient, $this->messageFactory, $this->serializer);
}
return $this->taskManager;
}
}