forked from KnpLabs/KnpGaufretteBundle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FilesystemMap.php
60 lines (53 loc) · 1.21 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
<?php
namespace Knp\Bundle\GaufretteBundle;
/**
* Holds references to all declared filesystems
* and allows to access them through their name.
*/
class FilesystemMap implements \IteratorAggregate
{
/**
* 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
*
* @return \Gaufrette\Filesystem
*
* @throw \InvalidArgumentException if the filesystem does not exist
*/
public function get($name)
{
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)
{
return isset($this->maps[$name]);
}
public function getIterator()
{
return new \ArrayIterator($this->maps);
}
}