Completed
Push — master ( a8c5d7...b64b96 )
by Arne
02:19
created

LocalStorageAdapter::getIdentificationString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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