KnpGaufretteBundle/FilesystemMap.php
2016-01-31 00:12:35 +01:00

61 lines
1.2 KiB
PHP

<?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 $map;
/**
* Instantiates a new filesystem map
*
* @param array $map
*/
public function __construct(array $map)
{
$this->map = $map;
}
/**
* 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 (!isset($this->map[$name])) {
throw new \InvalidArgumentException(sprintf('No filesystem register for name "%s"', $name));
}
return $this->map[$name];
}
/**
* @param string $name name of a filesystem
*
* @return bool
*/
public function has($name)
{
return isset($this->map[$name]);
}
public function getIterator()
{
return new \ArrayIterator($this->map);
}
}