-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFilesystemMap.php
54 lines (41 loc) · 1.23 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
<?php
namespace Coshi\MediaBundle;
use Gaufrette\FilesystemMap as BaseFilesystemMap;
class FilesystemMap extends BaseFilesystemMap
{
/**
* Name of the default files system
* @var string
*/
protected $default;
public function __construct(array $map = null, $defaultFilesystem = null)
{
//Set filesystems
foreach ($map as $domain => $filesystem) {
$this->set($domain, $filesystem);
}
$this->setDefault($defaultFilesystem);
}
public function setDefault($key)
{
if (!$this->has($key)) {
throw new \InvalidArgumentException(
sprintf('Default file system can not be set. \'%s\' domain dosent exists', $key)
);
}
$this->default = $key;
return $this;
}
public function getDefault()
{
if (is_null($this->default)) {
$filesystemKeys = array_keys($this->all());
$defaultKey = reset($filesystemKeys);
if (!$defaultKey) {
throw new \LogicException('Can not get default filesystem key');
}
$this->setDefault($defaultKey);
}
return $this->get($this->default);
}
}