1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Nexus\DockerClient; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Nexus\DockerClient\Communication\Command\Compose\DockerComposeRmCommand; |
8
|
|
|
use Nexus\DockerClient\Communication\Command\Compose\DockerComposeUpCommand; |
9
|
|
|
use Nexus\DockerClient\Communication\Command\Container\StartContainerCommand; |
10
|
|
|
use Nexus\DockerClient\Communication\Command\Container\StopContainerCommand; |
11
|
|
|
use Nexus\DockerClient\Communication\Command\Exec\DockerExecCommand; |
12
|
|
|
use Nexus\DockerClient\Communication\Command\Volume\VolumeCreateCommand; |
13
|
|
|
use Nexus\DockerClient\Communication\Command\Volume\VolumeRemoveCommand; |
14
|
|
|
use Xervice\Core\Dependency\DependencyProviderInterface; |
15
|
|
|
use Xervice\Core\Dependency\Provider\AbstractProvider; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @method \Xervice\Core\Locator\Locator getLocator() |
19
|
|
|
*/ |
20
|
|
|
class DockerClientDependencyProvider extends AbstractProvider |
21
|
|
|
{ |
22
|
|
|
const SHELL_FACADE = 'shell.facade'; |
23
|
|
|
|
24
|
|
|
const COMMAND_LIST = 'command.list'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param \Xervice\Core\Dependency\DependencyProviderInterface $container |
28
|
|
|
*/ |
29
|
|
|
public function handleDependencies(DependencyProviderInterface $container) |
30
|
|
|
{ |
31
|
|
|
$this->addShellFacade($container); |
|
|
|
|
32
|
|
|
|
33
|
|
|
$container[self::COMMAND_LIST] = function(DependencyProviderInterface $container) { |
|
|
|
|
34
|
|
|
return $this->getCommandList(); |
35
|
|
|
}; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
protected function getCommandList() |
42
|
|
|
{ |
43
|
|
|
return [ |
44
|
|
|
new DockerComposeUpCommand(), |
45
|
|
|
new DockerComposeRmCommand(), |
46
|
|
|
new VolumeCreateCommand(), |
47
|
|
|
new VolumeRemoveCommand(), |
48
|
|
|
new DockerExecCommand(), |
49
|
|
|
new StartContainerCommand(), |
50
|
|
|
new StopContainerCommand() |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param \Xervice\Core\Dependency\DependencyProviderInterface $container |
56
|
|
|
*/ |
57
|
|
|
private function addShellFacade(DependencyProviderInterface $container): void |
58
|
|
|
{ |
59
|
|
|
$container[self::SHELL_FACADE] = function(DependencyProviderInterface $container) { |
60
|
|
|
return $container->getLocator()->shell()->facade(); |
61
|
|
|
}; |
62
|
|
|
} |
63
|
|
|
} |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: