1 | <?php |
||
21 | class SSH extends AbstractProtocol |
||
22 | { |
||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $executable = "ssh"; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $host; |
||
32 | |||
33 | /** |
||
34 | * @var int |
||
35 | */ |
||
36 | protected $port = 22; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $username; |
||
42 | |||
43 | /** |
||
44 | * @var null |
||
45 | */ |
||
46 | protected $privateKey = null; |
||
47 | |||
48 | /** |
||
49 | * Injects and validates config |
||
50 | * |
||
51 | * @param array $options |
||
52 | */ |
||
53 | public function __construct(Array $options = array()) |
||
54 | { |
||
55 | $this->setOption($options, 'executable', 'setExecutable'); |
||
56 | $this->setOption($options, 'host', 'setHost'); |
||
57 | $this->setOption($options, 'port', 'setPort'); |
||
58 | $this->setOption($options, 'username', 'setUsername'); |
||
59 | $this->setOption($options, 'private_key', 'setPrivateKey'); |
||
60 | $this->setOption($options, 'public_key', 'setPrivateKey'); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @param $host |
||
65 | */ |
||
66 | public function setHost($host) |
||
67 | { |
||
68 | $this->host = $host; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @return mixed |
||
73 | */ |
||
74 | public function getHost() |
||
75 | { |
||
76 | return $this->host; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @param $port |
||
81 | * |
||
82 | * @throws \InvalidArgumentException If the port is not numeric |
||
83 | */ |
||
84 | public function setPort($port) |
||
85 | { |
||
86 | if (!is_int($port)) { |
||
87 | throw new \InvalidArgumentException("SSH port must be an integer"); |
||
88 | } |
||
89 | |||
90 | $this->port = $port; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @return int |
||
95 | */ |
||
96 | public function getPort() |
||
100 | |||
101 | /** |
||
102 | * @param $privateKey |
||
103 | * @throws \InvalidArgumentException |
||
104 | */ |
||
105 | public function setPrivateKey($privateKey) |
||
113 | |||
114 | /** |
||
115 | * @return string |
||
116 | */ |
||
117 | public function getPrivateKey() |
||
121 | |||
122 | /** |
||
123 | * @param $username |
||
124 | */ |
||
125 | public function setUsername($username) |
||
129 | |||
130 | /** |
||
131 | * @return string |
||
132 | */ |
||
133 | public function getUsername() |
||
137 | |||
138 | /** |
||
139 | * Gets commands for this SSH connection |
||
140 | * |
||
141 | * @param bool $hostConnection |
||
142 | * |
||
143 | * @return string |
||
144 | * |
||
145 | * @throws \InvalidArgumentException If you don't specify a SSH username or host |
||
146 | */ |
||
147 | public function getCommand($hostConnection = true) |
||
173 | |||
174 | /** |
||
175 | * Gets only connection options, without user@host string |
||
176 | * |
||
177 | * @return string |
||
178 | */ |
||
179 | public function getConnectionOptions() |
||
183 | |||
184 | /** |
||
185 | * Gets only host connection, without the rest |
||
186 | * of options |
||
187 | * |
||
188 | * @return string |
||
189 | */ |
||
190 | public function getHostConnection() |
||
194 | |||
195 | /** |
||
196 | * @param $executable |
||
197 | */ |
||
198 | public function setExecutable($executable) |
||
202 | |||
203 | /** |
||
204 | * @return string |
||
205 | */ |
||
206 | public function getExecutable() |
||
210 | |||
211 | /** |
||
212 | * @deprecated |
||
213 | */ |
||
214 | public function setPublicKey($privateKey) |
||
218 | |||
219 | /** |
||
220 | * @deprecated |
||
221 | */ |
||
222 | public function getPublicKey() |
||
226 | } |
||
227 |