Completed
Push — master ( 1d14da...d37c28 )
by Arne
02:16
created

Local::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 4
nc 3
nop 1
1
<?php
2
3
namespace Storeman\StorageAdapter;
4
5
use Storeman\Config\ConfigurationException;
6
use Storeman\PathUtils;
7
use Storeman\Config\VaultConfiguration;
8
use League\Flysystem\Filesystem;
9
10
class Local extends FlysystemStorageAdapter
11
{
12
    public function __construct(VaultConfiguration $vaultConfiguration)
13
    {
14
        if (!($path = $vaultConfiguration->getSetting('path')))
15
        {
16
            throw new ConfigurationException("Missing vault config setting 'path' for vault '{$vaultConfiguration->getTitle()}'.'");
17
        }
18
19
        $path = PathUtils::getAbsolutePath($path);
20
21
        if (!is_dir($path) || !is_writable($path))
22
        {
23
            throw new ConfigurationException(sprintf('Path "%s" does not exist or is not writable.', $path));
24
        }
25
26
        $adapter = new \League\Flysystem\Adapter\Local($path);
27
        $filesystem = new Filesystem($adapter);
28
29
        parent::__construct($filesystem);
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public static function getIdentificationString(VaultConfiguration $vaultConfiguration): string
36
    {
37
        return $vaultConfiguration->getSetting('path');
38
    }
39
}
40