1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Nexus\DockerClient; |
5
|
|
|
|
6
|
|
|
use Nexus\DockerClient\Communication\Command\Build\DockerBuildCommand; |
7
|
|
|
use Nexus\DockerClient\Communication\Command\Compose\DockerComposePullCommand; |
8
|
|
|
use Nexus\DockerClient\Communication\Command\Compose\DockerComposeRmCommand; |
9
|
|
|
use Nexus\DockerClient\Communication\Command\Compose\DockerComposeStopCommand; |
10
|
|
|
use Nexus\DockerClient\Communication\Command\Compose\DockerComposeUpCommand; |
11
|
|
|
use Nexus\DockerClient\Communication\Command\Container\StartContainerCommand; |
12
|
|
|
use Nexus\DockerClient\Communication\Command\Container\StopContainerCommand; |
13
|
|
|
use Nexus\DockerClient\Communication\Command\Copy\DockerCpCommand; |
14
|
|
|
use Nexus\DockerClient\Communication\Command\Exec\DockerExecCommand; |
15
|
|
|
use Nexus\DockerClient\Communication\Command\Restart\DockerRestartCommand; |
16
|
|
|
use Nexus\DockerClient\Communication\Command\Volume\VolumeCreateCommand; |
17
|
|
|
use Nexus\DockerClient\Communication\Command\Volume\VolumeRemoveCommand; |
18
|
|
|
use Xervice\Core\Business\Model\Dependency\DependencyContainerInterface; |
19
|
|
|
use Xervice\Core\Business\Model\Dependency\Provider\AbstractDependencyProvider; |
20
|
|
|
|
21
|
|
|
class DockerClientDependencyProvider extends AbstractDependencyProvider |
22
|
|
|
{ |
23
|
|
|
public const SHELL_FACADE = 'shell.facade'; |
24
|
|
|
public const COMMAND_LIST = 'command.list'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container |
28
|
|
|
* |
29
|
|
|
* @return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface |
30
|
|
|
*/ |
31
|
|
|
public function handleDependencies(DependencyContainerInterface $container): DependencyContainerInterface |
32
|
|
|
{ |
33
|
|
|
$container = $this->addShellFacade($container); |
34
|
|
|
$container = $this->addCommandList($container); |
35
|
|
|
|
36
|
|
|
return $container; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return array |
41
|
|
|
* @throws \Symfony\Component\Console\Exception\LogicException |
42
|
|
|
*/ |
43
|
|
|
protected function getCommandList(): array |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
new DockerComposeUpCommand(), |
47
|
|
|
new DockerComposeRmCommand(), |
48
|
|
|
new DockerComposePullCommand(), |
49
|
|
|
new DockerComposeStopCommand(), |
50
|
|
|
new VolumeCreateCommand(), |
51
|
|
|
new VolumeRemoveCommand(), |
52
|
|
|
new DockerExecCommand(), |
53
|
|
|
new StartContainerCommand(), |
54
|
|
|
new StopContainerCommand(), |
55
|
|
|
new DockerCpCommand(), |
56
|
|
|
new DockerBuildCommand(), |
57
|
|
|
new DockerRestartCommand() |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container |
63
|
|
|
* |
64
|
|
|
* @return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface |
65
|
|
|
*/ |
66
|
|
|
private function addShellFacade(DependencyContainerInterface $container): DependencyContainerInterface |
67
|
|
|
{ |
68
|
|
|
$container[self::SHELL_FACADE] = function (DependencyContainerInterface $container) { |
69
|
|
|
return $container->getLocator()->shell()->facade(); |
|
|
|
|
70
|
|
|
}; |
71
|
|
|
|
72
|
|
|
return $container; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container |
77
|
|
|
* |
78
|
|
|
* @return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface |
79
|
|
|
*/ |
80
|
|
|
protected function addCommandList( |
81
|
|
|
DependencyContainerInterface $container |
82
|
|
|
): DependencyContainerInterface { |
83
|
|
|
$container[self::COMMAND_LIST] = function (DependencyContainerInterface $container) { |
|
|
|
|
84
|
|
|
return $this->getCommandList(); |
85
|
|
|
}; |
86
|
|
|
|
87
|
|
|
return $container; |
88
|
|
|
} |
89
|
|
|
} |