-
Notifications
You must be signed in to change notification settings - Fork 158
/
FilesystemMap.php
61 lines (53 loc) · 1.3 KB
/
FilesystemMap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Knp\Bundle\GaufretteBundle;
use Gaufrette\FilesystemInterface;
use Gaufrette\FilesystemMapInterface;
/**
* Holds references to all declared filesystems
* and allows to access them through their name.
*/
class FilesystemMap implements \IteratorAggregate, FilesystemMapInterface
{
/**
* Map of filesystems indexed by their name.
*
* @var array
*/
protected $maps;
/**
* Instantiates a new filesystem map.
*
* @param array $maps
*/
public function __construct(array $maps)
{
$this->maps = $maps;
}
/**
* Retrieves a filesystem by its name.
*
* @param string $name name of a filesystem
*
* @throw \InvalidArgumentException if the filesystem does not exist
*/
public function get($name): FilesystemInterface
{
if (!$this->has($name)) {
throw new \InvalidArgumentException(sprintf('No filesystem is registered for name "%s"', $name));
}
return $this->maps[$name];
}
/**
* @param string $name name of a filesystem
*
* @return bool
*/
public function has($name): bool
{
return isset($this->maps[$name]);
}
public function getIterator(): \Traversable
{
return new \ArrayIterator($this->maps);
}
}