|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Spiral Framework package. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Spiral\Storage\Builder\Adapter; |
|
13
|
|
|
|
|
14
|
|
|
use League\Flysystem\FilesystemAdapter; |
|
15
|
|
|
use League\Flysystem\UnixVisibility\PortableVisibilityConverter; |
|
16
|
|
|
use Spiral\Storage\Config\DTO\FileSystemInfo\LocalInfo; |
|
17
|
|
|
use Spiral\Storage\Config\DTO\FileSystemInfo\FileSystemInfoInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @property FileSystemInfoInterface|LocalInfo $fsInfo |
|
21
|
|
|
*/ |
|
22
|
|
|
class LocalBuilder extends AbstractBuilder |
|
23
|
|
|
{ |
|
24
|
|
|
protected const FILE_SYSTEM_INFO_CLASS = LocalInfo::class; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @inheritDoc |
|
28
|
|
|
*/ |
|
29
|
|
|
public function buildSimple(): FilesystemAdapter |
|
30
|
|
|
{ |
|
31
|
|
|
$adapterClass = $this->fsInfo->getAdapterClass(); |
|
32
|
|
|
|
|
33
|
|
|
return new $adapterClass( |
|
34
|
|
|
$this->fsInfo->getOption(LocalInfo::ROOT_DIR_KEY) |
|
|
|
|
|
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @inheritDoc |
|
40
|
|
|
*/ |
|
41
|
|
|
public function buildAdvanced(): FilesystemAdapter |
|
42
|
|
|
{ |
|
43
|
|
|
$adapterClass = $this->fsInfo->getAdapterClass(); |
|
44
|
|
|
|
|
45
|
|
|
return new $adapterClass( |
|
46
|
|
|
$this->fsInfo->getOption(LocalInfo::ROOT_DIR_KEY), |
|
47
|
|
|
$this->fsInfo->hasOption(LocalInfo::VISIBILITY_KEY) |
|
|
|
|
|
|
48
|
|
|
? PortableVisibilityConverter::fromArray($this->fsInfo->getOption(LocalInfo::VISIBILITY_KEY)) |
|
|
|
|
|
|
49
|
|
|
: null, |
|
50
|
|
|
$this->fsInfo->hasOption(LocalInfo::WRITE_FLAGS_KEY) |
|
51
|
|
|
? $this->fsInfo->getOption(LocalInfo::WRITE_FLAGS_KEY) |
|
52
|
|
|
: \LOCK_EX, |
|
53
|
|
|
$this->fsInfo->hasOption(LocalInfo::LINK_HANDLING_KEY) |
|
54
|
|
|
? $this->fsInfo->getOption(LocalInfo::LINK_HANDLING_KEY) |
|
55
|
|
|
: $adapterClass::DISALLOW_LINKS |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|