Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
66.67% |
14 / 21 |
CRAP | |
75.00% |
36 / 48 |
DockerConfig | |
0.00% |
0 / 1 |
|
66.67% |
14 / 21 |
40.25 | |
75.00% |
36 / 48 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
setCommand | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getCommand | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
getCompleteCommand | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
setScheduleName | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getScheduleName | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
setDockerImage | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getDockerImage | |
0.00% |
0 / 1 |
2.15 | |
66.67% |
2 / 3 |
|||
setOutputFile | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getOutputFile | |
0.00% |
0 / 1 |
3.33 | |
66.67% |
4 / 6 |
|||
setCommandLauncher | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getCommandLauncher | |
0.00% |
0 / 1 |
2.15 | |
66.67% |
2 / 3 |
|||
setMountPoint | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
getMountPoints | |
0.00% |
0 / 1 |
2.15 | |
66.67% |
2 / 3 |
|||
getBashCommand | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
getBashArgs | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
setEnvs | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getEnvs | |
0.00% |
0 / 1 |
2.15 | |
66.67% |
2 / 3 |
|||
getRestartPolicy | |
0.00% |
0 / 1 |
2.15 | |
66.67% |
2 / 3 |
|||
setRestartPolicy | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getAuthorizedNetworksList | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\DockerLauncher\Docker; |
4 | |
5 | use Illuminate\Support\Facades\Log; |
6 | |
7 | class DockerConfig |
8 | { |
9 | private $config = []; |
10 | |
11 | private $scheduleName; |
12 | |
13 | private $command; |
14 | |
15 | public function __construct(array $config) |
16 | { |
17 | $this->config = $config; |
18 | } |
19 | |
20 | public function setCommand(string $command) |
21 | { |
22 | $this->command = $command; |
23 | } |
24 | |
25 | public function getCommand() |
26 | { |
27 | return $this->command; |
28 | } |
29 | |
30 | public function getCompleteCommand() |
31 | { |
32 | return (string) $this->getCommandLauncher() . ' ' . (string) $this->getCommand(); |
33 | } |
34 | |
35 | /** |
36 | * @param string $scheduleName |
37 | */ |
38 | public function setScheduleName(string $scheduleName) |
39 | { |
40 | $this->scheduleName = $scheduleName; |
41 | } |
42 | |
43 | public function getScheduleName() |
44 | { |
45 | return $this->scheduleName; |
46 | } |
47 | |
48 | /** |
49 | * @param string $image |
50 | */ |
51 | public function setDockerImage(string $image) |
52 | { |
53 | $this->config['image'] = $image; |
54 | } |
55 | |
56 | public function getDockerImage() |
57 | { |
58 | if (isset($this->config['image'])) { |
59 | return $this->config['image']; |
60 | } |
61 | |
62 | return null; |
63 | } |
64 | |
65 | public function setOutputFile(string $output) |
66 | { |
67 | $this->config['output'] = $output; |
68 | } |
69 | |
70 | public function getOutputFile() |
71 | { |
72 | if (isset($this->config['output'])) { |
73 | $directory = implode('/', array_slice(explode('/', $this->config['output']), 0, -1)); |
74 | |
75 | if (!\File::exists( $directory)) { |
76 | \File::makeDirectory($directory, 0777, true); |
77 | } |
78 | |
79 | return $this->config['output']; |
80 | } |
81 | |
82 | return null; |
83 | } |
84 | |
85 | public function setCommandLauncher(string $command) |
86 | { |
87 | $this->config['command'] = $command; |
88 | } |
89 | |
90 | public function getCommandLauncher() |
91 | { |
92 | if (isset($this->config['command'])) { |
93 | return $this->config['command']; |
94 | } |
95 | |
96 | return null; |
97 | } |
98 | |
99 | public function setMountPoint(string $source, string $target, string $type) |
100 | { |
101 | $this->config['mount'] = [ |
102 | 'source' => $source, |
103 | 'target' => $target, |
104 | 'type' => $type |
105 | ]; |
106 | } |
107 | |
108 | public function getMountPoints() |
109 | { |
110 | if (isset($this->config['mounts'])) { |
111 | return $this->config['mounts']; |
112 | } |
113 | |
114 | return null; |
115 | } |
116 | |
117 | public function getBashCommand() |
118 | { |
119 | return ['/bin/bash', '-c']; |
120 | } |
121 | |
122 | public function getBashArgs() |
123 | { |
124 | return [$this->getCompleteCommand() . ' >> ' . $this->getOutputFile()]; |
125 | } |
126 | |
127 | |
128 | public function setEnvs(array $envs) |
129 | { |
130 | $this->config['envs'] = $envs; |
131 | } |
132 | |
133 | public function getEnvs() { |
134 | if (isset($this->config['envs'])) { |
135 | return $this->config['envs']; |
136 | } |
137 | |
138 | return null; |
139 | } |
140 | |
141 | public function getRestartPolicy() { |
142 | if (isset($this->config['restart-policy'])) { |
143 | return $this->config['restart-policy']; |
144 | } |
145 | |
146 | return null; |
147 | } |
148 | |
149 | public function setRestartPolicy($policy) { |
150 | $this->config['restart-policy'] = $policy; |
151 | } |
152 | |
153 | public function getAuthorizedNetworksList() |
154 | { |
155 | return $this->config['networks']; |
156 | } |
157 | } |