1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* BsbFlystem |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @see https://bushbaby.nl/ |
10
|
|
|
* |
11
|
|
|
* @copyright Copyright (c) 2014-2021 bushbaby multimedia. (https://bushbaby.nl) |
12
|
|
|
* @author Bas Kamer <[email protected]> |
13
|
|
|
* @license MIT |
14
|
|
|
* |
15
|
1 |
|
* @package bushbaby/flysystem |
16
|
|
|
*/ |
17
|
1 |
|
|
18
|
|
|
declare(strict_types=1); |
19
|
|
|
|
20
|
|
|
namespace BsbFlysystem\Adapter\Factory; |
21
|
|
|
|
22
|
|
|
use BsbFlysystem\Exception\RequirementsException; |
23
|
|
|
use BsbFlysystem\Exception\UnexpectedValueException; |
24
|
1 |
|
use League\Flysystem\AdapterInterface; |
25
|
|
|
use League\Flysystem\Sftp\SftpAdapter as Adapter; |
26
|
1 |
|
use Psr\Container\ContainerInterface; |
27
|
|
|
|
28
|
|
|
class SftpAdapterFactory extends AbstractAdapterFactory |
29
|
7 |
|
{ |
30
|
|
|
public function doCreateService(ContainerInterface $container): AdapterInterface |
31
|
7 |
|
{ |
32
|
1 |
|
if (! \class_exists(Adapter::class)) { |
33
|
|
|
throw new RequirementsException(['league/flysystem-sftp'], 'Sftp'); |
34
|
|
|
} |
35
|
6 |
|
|
36
|
1 |
|
return new Adapter($this->options); |
37
|
|
|
} |
38
|
|
|
|
39
|
5 |
|
protected function validateConfig(): void |
40
|
1 |
|
{ |
41
|
|
|
if (! isset($this->options['host'])) { |
42
|
|
|
throw new UnexpectedValueException("Missing 'host' as option"); |
43
|
4 |
|
} |
44
|
1 |
|
|
45
|
|
|
if (! isset($this->options['port'])) { |
46
|
3 |
|
throw new UnexpectedValueException("Missing 'port' as option"); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if (! isset($this->options['username'])) { |
50
|
|
|
throw new UnexpectedValueException("Missing 'username' as option"); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if (! isset($this->options['password']) && ! isset($this->options['privateKey'])) { |
54
|
|
|
throw new UnexpectedValueException("Missing either 'password' or 'privateKey' as option"); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|