Completed
Push — master ( a8a6e5...b4d61a )
by Arne
04:19
created

LocalStorageAdapter::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 3
nop 1
1
<?php
2
3
namespace Archivr\StorageAdapter;
4
5
use Archivr\Exception\ConfigurationException;
6
use Archivr\PathUtils;
7
use Archivr\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