|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Micro framework package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Stanislau Komar <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Micro\Plugin\Filesystem\Adapter\Local\Business\Adapter; |
|
15
|
|
|
|
|
16
|
|
|
use League\Flysystem\FilesystemAdapter; |
|
17
|
|
|
use League\Flysystem\Local\LocalFilesystemAdapter; |
|
18
|
|
|
use League\Flysystem\UnixVisibility\PortableVisibilityConverter; |
|
19
|
|
|
use Micro\Plugin\Filesystem\Adapter\Local\Configuration\Adapter\LocalAdapterConfigurationInterface; |
|
20
|
|
|
use Micro\Plugin\Filesystem\Business\Adapter\AdapterFactoryInterface; |
|
21
|
|
|
use Micro\Plugin\Filesystem\Configuration\Adapter\FilesystemAdapterConfigurationInterface; |
|
22
|
|
|
|
|
23
|
|
|
class AdapterFactory implements AdapterFactoryInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @param FilesystemAdapterConfigurationInterface $adapterConfiguration |
|
27
|
|
|
* |
|
28
|
|
|
* @return FilesystemAdapter |
|
29
|
|
|
*/ |
|
30
|
1 |
|
public function create(FilesystemAdapterConfigurationInterface $adapterConfiguration): FilesystemAdapter |
|
31
|
|
|
{ |
|
32
|
1 |
|
if (!($adapterConfiguration instanceof LocalAdapterConfigurationInterface)) { |
|
33
|
|
|
throw new \InvalidArgumentException(sprintf('Adapter configuration should be instance of %s.', LocalAdapterConfigurationInterface::class)); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
1 |
|
$additionalConfig = array_filter([ |
|
37
|
1 |
|
'file' => $this->createAccessDataArray( |
|
38
|
1 |
|
$adapterConfiguration->getPermissionPublicFile(), |
|
39
|
1 |
|
$adapterConfiguration->getPermissionPrivateFile() |
|
40
|
1 |
|
), |
|
41
|
1 |
|
'dir' => $this->createAccessDataArray( |
|
42
|
1 |
|
$adapterConfiguration->getPermissionPublicDirectory(), |
|
43
|
1 |
|
$adapterConfiguration->getPermissionPrivateDirectory(), |
|
44
|
1 |
|
), |
|
45
|
1 |
|
]); |
|
46
|
|
|
|
|
47
|
1 |
|
$additionalConfig = !empty($additionalConfig) ? |
|
48
|
1 |
|
PortableVisibilityConverter::fromArray($additionalConfig) : |
|
49
|
|
|
null; |
|
50
|
|
|
|
|
51
|
1 |
|
return new LocalFilesystemAdapter( |
|
52
|
1 |
|
$adapterConfiguration->getRootDirectory(), |
|
53
|
1 |
|
$additionalConfig, |
|
54
|
1 |
|
$adapterConfiguration->getWriteFlags(), |
|
55
|
1 |
|
$adapterConfiguration->getLinkHeading(), |
|
56
|
1 |
|
null, |
|
57
|
1 |
|
$adapterConfiguration->isLazyRootCreation(), |
|
58
|
1 |
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param int $public |
|
63
|
|
|
* @param int $private |
|
64
|
|
|
* |
|
65
|
|
|
* @return array<string|int> |
|
66
|
|
|
*/ |
|
67
|
1 |
|
protected function createAccessDataArray(int $public, int $private): array |
|
68
|
|
|
{ |
|
69
|
1 |
|
return array_filter([ |
|
70
|
1 |
|
'public' => $public, |
|
71
|
1 |
|
'private' => $private, |
|
72
|
1 |
|
]); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|