Completed
Push — master ( 97f3ba...baa78e )
by Kamil
03:56
created

FilesystemManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Dazzle\Filesystem;
4
5
class FilesystemManager implements FilesystemManagerInterface
6
{
7
    /**
8
     * @var FilesystemInterface[]
9
     */
10
    protected $filesystems;
11
12
    /**
13
     * @param FilesystemInterface[] $filesystems
14
     */
15
    public function __construct($filesystems = [])
16
    {
17
        $this->mountFilesystems($filesystems);
18
    }
19
20
    /**
21
     *
22
     */
23
    public function __destruct()
24
    {
25
        unset($this->filesystems);
26
    }
27
28
    /**
29
     * @override
30
     * @inheritDoc
31
     */
32
    public function mountFilesystems($filesystems)
33
    {
34
        foreach ($filesystems as $prefix=>$filesystem)
35
        {
36
            $this->mountFilesystem($prefix, $filesystem);
37
        }
38
    }
39
40
    /**
41
     * @override
42
     * @inheritDoc
43
     */
44
    public function existsFilesystem($prefix)
45
    {
46
        return isset($this->filesystems[$prefix]);
47
    }
48
49
    /**
50
     * @override
51
     * @inheritDoc
52
     */
53
    public function mountFilesystem($prefix, FilesystemInterface $filesystem)
54
    {
55
        $this->filesystems[$prefix] = $filesystem;
56
    }
57
58
    /**
59
     * @override
60
     * @inheritDoc
61
     */
62
    public function unmountFilesystem($prefix)
63
    {
64
        unset($this->filesystems[$prefix]);
65
    }
66
67
    /**
68
     * @override
69
     * @inheritDoc
70
     */
71
    public function getFilesystem($prefix)
72
    {
73
        if (!$this->existsFilesystem($prefix))
74
        {
75
            return null;
76
        }
77
78
        return $this->filesystems[$prefix];
79
    }
80
}
81