forked from meinfernbus/GoogleBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapsManager.php
98 lines (81 loc) · 1.97 KB
/
MapsManager.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
96
97
98
<?php
namespace AntiMattr\GoogleBundle;
use AntiMattr\GoogleBundle\Maps\MapInterface;
use Doctrine\Common\Collections\Collection;
class MapsManager
{
private $config = array();
private $maps = array();
public function __construct(array $config = array())
{
$this->config = $config;
}
public function setKey($key)
{
$this->config['key'] = $key;
}
public function getKey()
{
if (array_key_exists('key', $this->config)) {
return $this->config['key'];
}
}
public function hasMaps()
{
if (!empty($this->maps)) {
return true;
}
return false;
}
public function hasMap(MapInterface $map)
{
if ($this->maps instanceof Collection) {
return $this->maps->contains($map);
} else {
return in_array($map, $this->maps, true);
}
}
public function addMap(MapInterface $map)
{
$this->maps[] = $map;
}
public function createStaticMap()
{
$map = new Maps\StaticMap();
if (isset($this->config['key'])) {
$map->setKey($this->config['key']);
}
if (isset($this->config['host'])) {
$map->setHost($this->config['host']);
}
return $map;
}
public function removeMap(MapInterface $map)
{
if (!$this->hasMap($map)) {
return null;
}
if ($this->maps instanceof Collection) {
return $this->maps->removeElement($map);
} else {
unset($this->maps[array_search($map, $this->maps, true)]);
return $map;
}
}
public function setMaps($maps)
{
$this->maps = $maps;
}
public function getMaps()
{
return $this->maps;
}
public function getMapById($id)
{
foreach ($this->maps as $map) {
if ($id == $map->getId()) {
return $map;
}
}
}
}