| 1 | <?php |
||
| 9 | abstract class SoftwareInstallTask extends InstallerTask implements NamedChainProcessInterface |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var ProcessRunner |
||
| 13 | */ |
||
| 14 | protected $processRunner; |
||
| 15 | /** |
||
| 16 | * @var UserInteraction |
||
| 17 | */ |
||
| 18 | protected $userInteraction; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param UserInteraction $userInteraction |
||
| 22 | * @param \Dock\IO\ProcessRunner $processRunner |
||
| 23 | */ |
||
| 24 | public function __construct(UserInteraction $userInteraction, ProcessRunner $processRunner) |
||
| 25 | { |
||
| 26 | $this->userInteraction = $userInteraction; |
||
| 27 | $this->processRunner = $processRunner; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * {@inheritdoc} |
||
| 32 | */ |
||
| 33 | public function run() |
||
| 34 | { |
||
| 35 | if ($this->processRunner->run($this->getVersionCommand(), false)->isSuccessful()) { |
||
| 36 | $this->userInteraction->write(sprintf('"%s" is already installed', $this->getName())); |
||
| 37 | } else { |
||
| 38 | $this->userInteraction->write(sprintf('Installing "%s"', $this->getName())); |
||
| 39 | $this->processRunner->run($this->getInstallCommand()); |
||
| 40 | $this->userInteraction->write(sprintf('"%s" successfully installed', $this->getName())); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @return string |
||
| 46 | */ |
||
| 47 | abstract protected function getVersionCommand(); |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @return string |
||
| 51 | */ |
||
| 52 | abstract protected function getInstallCommand(); |
||
| 53 | } |
||
| 54 |