Skip to content

Commit f939157

Browse files
committed
Initial class structure
1 parent e773e96 commit f939157

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
vendor/
3+
composer.lock

src/SSHConnection.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
}

0 commit comments

Comments
 (0)