forked from geocoder-php/BazingaGeocoderBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DumperManager.php
95 lines (83 loc) · 2.03 KB
/
DumperManager.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* This file is part of the BazingaGeocoderBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace Bazinga\Bundle\GeocoderBundle;
use Geocoder\Dumper\DumperInterface;
/**
* @author Markus Bachmann <markus.bachmann@bachi.biz>
*/
class DumperManager
{
/**
* @var array
*/
private $dumpers;
/**
* Constructor
*
* @param array $dumpers
*/
public function __construct(array $dumpers = array())
{
$this->dumpers = array();
foreach ($dumpers as $name => $dumper) {
$this->set($name, $dumper);
}
}
/**
* Get a dumper
*
* @param string $name The name of the dumper
*
* @return DumperInterface
*
* @throws \RuntimeException If no dumper was found
*/
public function get($name)
{
if (!isset($this->dumpers[$name])) {
throw new \RuntimeException(sprintf('The dumper "%s" does not exist', $name));
}
return $this->dumpers[$name];
}
/**
* Sets a dumper
*
* @param string $name The name
* @param DumperInterface $dumper The dumper instance
*/
public function set($name, DumperInterface $dumper)
{
$this->dumpers[$name] = $dumper;
}
/**
* Remove a dumper instance from the manager
*
* @param string $name The name of the dumper
*
* @throws \RuntimeException If no dumper was found
*/
public function remove($name)
{
if (!isset($this->dumpers[$name])) {
throw new \RuntimeException(sprintf('The dumper "%s" does not exist', $name));
}
unset($this->dumpers[$name]);
}
/**
* Return true if $name exists, false otherwise.
*
* @param $name The name of the dumper
*
* @return bool
*/
public function has($name)
{
return array_key_exists($name, $this->dumpers);
}
}