-
Notifications
You must be signed in to change notification settings - Fork 0
/
Container.php
72 lines (58 loc) · 1.39 KB
/
Container.php
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
<?php
namespace dophpsdk;
/**
* dophpsdk\Container
*/
class Container {
private $data;
public $debug = FALSE;
/**
* Container constructor.
*
* @param array $settings
*
* $settings = [
* "Id" => "ea1720f9eb0a6f074f84a6253db9ebd095315edd8da877cadc61051dba78e511",
* "Name" => "drupal_4",
* "Config" => [
* "Image" => "drupal:8.4.3"
* ]
* ];
*/
public function __construct($settings) {
$docker = new Docker();
if (isset($settings["Id"])) {
$unique = $settings["Id"];
}
else if (isset($settings["Name"])) {
$unique = $settings["Name"];
}
if (isset($unique)) {
$inspect = $docker->ContainerInspect($unique);
if ($inspect) {
$inspect = array_shift(array_values($inspect));
$this->setConfig($inspect);
}
else if (isset($settings["Config"]["Image"])) {
$image = $settings["Config"]["Image"];
$name = $settings["Name"];
$container = $docker->ContainerRun($image, $name);
$data = $docker->ContainerInspect($container[0]);
$data = array_shift(array_values($data));
$this->setConfig($data);
}
}
}
/**
* @param mixed $data
*/
public function setConfig($data) {
$this->data = $data;
}
/**
* @return mixed
*/
public function getConfig() {
return $this->data;
}
}