File tree Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Original file line number Diff line number Diff line change 1+ .idea
2+ vendor /
3+ composer.lock
Original file line number Diff line number Diff line change 1+ <?php
2+
3+
4+ namespace DivineOmega \SSHConnection ;
5+
6+
7+ class SSHConnection
8+ {
9+ private $ hostname ;
10+ private $ port = 22 ;
11+ private $ username ;
12+ private $ password ;
13+ private $ publicKeyPath ;
14+ private $ privateKeyPath ;
15+ private $ connected ;
16+
17+ public function to (string $ hostname ): self
18+ {
19+ $ this ->hostname = $ hostname ;
20+ return $ this ;
21+ }
22+
23+ public function onPort (int $ port ): self
24+ {
25+ $ this ->port = $ port ;
26+ return $ this ;
27+ }
28+
29+ public function as (string $ username ): self
30+ {
31+ $ this ->username = $ username ;
32+ return $ this ;
33+ }
34+
35+ public function withPassword (string $ password ): self
36+ {
37+ $ this ->password = $ password ;
38+ return $ this ;
39+ }
40+
41+ public function withKeyPair (string $ publicKeyPath , string $ privateKeyPath ): self
42+ {
43+ $ this ->publicKeyPath = $ publicKeyPath ;
44+ $ this ->privateKeyPath = $ privateKeyPath ;
45+ return $ this ;
46+ }
47+
48+ public function connect ()
49+ {
50+ // TODO: Sanity check required variables.
51+ // TODO: Make SSH connection.
52+
53+ $ this ->connected = true ;
54+ }
55+
56+ public function run ($ commands )
57+ {
58+ if (is_string ($ commands )) {
59+ $ commands = [$ commands ];
60+ }
61+
62+ if (!is_array ($ commands )) {
63+ throw new \InvalidArgumentException ('Command(s) passed should be a string or array. ' );
64+ }
65+
66+ if (!$ this ->connected ) {
67+ throw new \RuntimeException ('Unable to run commands when not connected. ' );
68+ }
69+
70+ // TODO: Execute commands
71+ }
72+ }
You can’t perform that action at this time.
0 commit comments