-
Notifications
You must be signed in to change notification settings - Fork 96
/
StubSftpConnectionProvider.php
62 lines (50 loc) · 1.24 KB
/
StubSftpConnectionProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare(strict_types=1);
namespace League\Flysystem\PhpseclibV2;
use phpseclib\Net\SFTP;
/**
* @deprecated The "League\Flysystem\PhpseclibV2\StubSftpConnectionProvider" class is deprecated since Flysystem 3.0, use "League\Flysystem\PhpseclibV3\StubSftpConnectionProvider" instead.
*/
class StubSftpConnectionProvider implements ConnectionProvider
{
/**
* @var string
*/
private $host;
/**
* @var string
*/
private $username;
/**
* @var string|null
*/
private $password;
/**
* @var int
*/
private $port;
/**
* @var SftpStub
*/
private $connection;
public function __construct(
string $host,
string $username,
?string $password = null,
int $port = 22
) {
$this->host = $host;
$this->username = $username;
$this->password = $password;
$this->port = $port;
}
public function provideConnection(): SFTP
{
if ( ! $this->connection instanceof SFTP) {
$connection = new SftpStub($this->host, $this->port);
$connection->login($this->username, $this->password);
$this->connection = $connection;
}
return $this->connection;
}
}