2011-06-18 18:49:55 +00:00
|
|
|
<?php
|
|
|
|
|
2011-07-03 09:38:38 +00:00
|
|
|
namespace Knp\Bundle\GaufretteBundle;
|
2011-06-18 18:49:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Holds references to all declared filesystems
|
2016-02-04 07:27:14 +00:00
|
|
|
* and allows to access them through their name.
|
2011-06-18 18:49:55 +00:00
|
|
|
*/
|
2012-10-30 14:07:34 +00:00
|
|
|
class FilesystemMap implements \IteratorAggregate
|
2011-06-18 18:49:55 +00:00
|
|
|
{
|
|
|
|
/**
|
2016-02-04 07:27:14 +00:00
|
|
|
* Map of filesystems indexed by their name.
|
2011-06-18 18:49:55 +00:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2016-02-04 07:27:14 +00:00
|
|
|
protected $maps;
|
2011-06-18 18:49:55 +00:00
|
|
|
|
|
|
|
/**
|
2016-02-04 07:27:14 +00:00
|
|
|
* Instantiates a new filesystem map.
|
2011-06-18 18:49:55 +00:00
|
|
|
*
|
2016-02-04 07:27:14 +00:00
|
|
|
* @param array $maps
|
2011-06-18 18:49:55 +00:00
|
|
|
*/
|
2016-02-04 07:27:14 +00:00
|
|
|
public function __construct(array $maps)
|
2011-06-18 18:49:55 +00:00
|
|
|
{
|
2016-02-04 07:27:14 +00:00
|
|
|
$this->maps = $maps;
|
2011-06-18 18:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-10-30 14:07:34 +00:00
|
|
|
* Retrieves a filesystem by its name.
|
|
|
|
*
|
2011-06-18 18:49:55 +00:00
|
|
|
* @param string $name name of a filesystem
|
2012-10-30 14:07:34 +00:00
|
|
|
*
|
|
|
|
* @return \Gaufrette\Filesystem
|
|
|
|
*
|
2011-06-18 18:49:55 +00:00
|
|
|
* @throw \InvalidArgumentException if the filesystem does not exist
|
|
|
|
*/
|
|
|
|
public function get($name)
|
|
|
|
{
|
2016-02-04 07:27:14 +00:00
|
|
|
if (!$this->has($name)) {
|
|
|
|
throw new \InvalidArgumentException(sprintf('No filesystem is registered for name "%s"', $name));
|
2011-06-18 18:49:55 +00:00
|
|
|
}
|
|
|
|
|
2016-02-04 07:27:14 +00:00
|
|
|
return $this->maps[$name];
|
2011-06-18 18:49:55 +00:00
|
|
|
}
|
2012-10-30 14:07:34 +00:00
|
|
|
|
2016-01-30 23:12:35 +00:00
|
|
|
/**
|
|
|
|
* @param string $name name of a filesystem
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function has($name)
|
|
|
|
{
|
2016-02-04 07:27:14 +00:00
|
|
|
return isset($this->maps[$name]);
|
2016-01-30 23:12:35 +00:00
|
|
|
}
|
|
|
|
|
2012-10-30 14:07:34 +00:00
|
|
|
public function getIterator()
|
|
|
|
{
|
2016-02-04 07:27:14 +00:00
|
|
|
return new \ArrayIterator($this->maps);
|
2012-10-30 14:07:34 +00:00
|
|
|
}
|
2011-06-18 18:49:55 +00:00
|
|
|
}
|