1 | <?php |
||
11 | class PhpSsh extends InstallerTask implements DependentChainProcessInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var ProcessRunner |
||
15 | */ |
||
16 | private $processRunner; |
||
17 | /** |
||
18 | * @var UserInteraction |
||
19 | */ |
||
20 | private $userInteraction; |
||
21 | |||
22 | /** |
||
23 | * @param UserInteraction $userInteraction |
||
24 | * @param \Dock\IO\ProcessRunner $processRunner |
||
25 | */ |
||
26 | public function __construct(UserInteraction $userInteraction, ProcessRunner $processRunner) |
||
27 | { |
||
28 | $this->userInteraction = $userInteraction; |
||
29 | $this->processRunner = $processRunner; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | public function getName() |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | public function dependsOn() |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | public function run() |
||
52 | { |
||
53 | $this->userInteraction->writeTitle('Checking PHP SSH2 extension'); |
||
54 | |||
55 | if ($this->sshExtensionInstalled()) { |
||
56 | return; |
||
57 | } |
||
58 | |||
59 | $this->userInteraction->write('PHP SSH2 extension is required.'); |
||
60 | |||
61 | $package = $this->promptForPackageName(); |
||
62 | |||
63 | if ($package == 'n') { |
||
64 | $this->userInteraction->write('Skipping PHP SSH2 extension installation, do it yourself.'); |
||
65 | } else { |
||
66 | $this->installHomebrewPackage($package); |
||
67 | } |
||
68 | |||
69 | throw new \RuntimeException('Please re-run this installation script to have enabled PHP-SSH2 extension'); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @return string |
||
74 | */ |
||
75 | private function guessSsh2PhpPackage() |
||
89 | |||
90 | /** |
||
91 | * @param string $package |
||
92 | * |
||
93 | * @return bool |
||
94 | */ |
||
95 | private function hasHomebrewPackage($package) |
||
99 | |||
100 | /** |
||
101 | * @return bool |
||
102 | */ |
||
103 | private function sshExtensionInstalled() |
||
107 | |||
108 | /** |
||
109 | * @param $package |
||
110 | */ |
||
111 | protected function installHomebrewPackage($package) |
||
124 | |||
125 | /** |
||
126 | * @return string |
||
127 | */ |
||
128 | protected function promptForPackageName() |
||
142 | } |
||
143 |