KnpGaufretteBundle/FilesystemMap.php

61 lines
1.2 KiB
PHP
Raw Permalink 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
2016-02-04 07:27:14 +00:00
* and allows to access them through their name.
2011-06-18 18:49:55 +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
}
/**
* 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)
{
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
}
/**
* @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]);
}
public function getIterator()
{
2016-02-04 07:27:14 +00:00
return new \ArrayIterator($this->maps);
}
2011-06-18 18:49:55 +00:00
}