KnpGaufretteBundle/FilesystemMap.php

61 lines
1.2 KiB
PHP
Raw Normal View History

2011-06-18 18:49:55 +00:00
<?php
namespace Knp\Bundle\GaufretteBundle;
2011-06-18 18:49:55 +00:00
/**
* Holds references to all declared filesystems
* and allows to access them through their name
*/
class FilesystemMap implements \IteratorAggregate
2011-06-18 18:49:55 +00:00
{
/**
* Map of filesystems indexed by their name
*
* @var array
*/
protected $map;
2011-06-18 18:49:55 +00:00
/**
* Instantiates a new filesystem map
2011-06-18 18:49:55 +00:00
*
* @param array $map
*/
public function __construct(array $map)
{
$this->map = $map;
}
/**
* Retrieves a filesystem by its name.
*
2011-06-18 18:49:55 +00:00
* @param string $name name of a filesystem
*
* @return \Gaufrette\Filesystem
*
2011-06-18 18:49:55 +00:00
* @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);
}
2011-06-18 18:49:55 +00:00
}