1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Google Map package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivory\GoogleMap\Helper; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Helper\Event\StaticMapEvent; |
15
|
|
|
use Ivory\GoogleMap\Helper\Event\StaticMapEvents; |
16
|
|
|
use Ivory\GoogleMap\Map; |
17
|
|
|
use Ivory\GoogleMap\Service\UrlSigner; |
18
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author GeLo <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class StaticMapHelper extends AbstractHelper |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var string|null |
27
|
|
|
*/ |
28
|
|
|
private $secret; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string|null |
32
|
|
|
*/ |
33
|
|
|
private $clientId; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string|null |
37
|
|
|
*/ |
38
|
|
|
private $channel; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string|null $secret |
42
|
|
|
* @param string|null $clientId |
43
|
|
|
* @param string|null $channel |
44
|
|
|
*/ |
45
|
4 |
|
public function __construct( |
46
|
|
|
EventDispatcherInterface $eventDispatcher, |
47
|
|
|
$secret = null, |
48
|
|
|
$clientId = null, |
49
|
|
|
$channel = null |
50
|
|
|
) { |
51
|
4 |
|
parent::__construct($eventDispatcher); |
52
|
|
|
|
53
|
4 |
|
$this->secret = $secret; |
54
|
4 |
|
$this->clientId = $clientId; |
55
|
4 |
|
$this->channel = $channel; |
56
|
4 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return bool |
60
|
|
|
*/ |
61
|
|
|
public function hasSecret() |
62
|
|
|
{ |
63
|
|
|
return null !== $this->secret; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return string|null |
68
|
|
|
*/ |
69
|
|
|
public function getSecret() |
70
|
|
|
{ |
71
|
|
|
return $this->secret; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string|null $secret |
76
|
|
|
*/ |
77
|
|
|
public function setSecret($secret) |
78
|
|
|
{ |
79
|
|
|
$this->secret = $secret; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
|
|
public function hasClientId() |
86
|
|
|
{ |
87
|
|
|
return null !== $this->clientId; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return string|null |
92
|
|
|
*/ |
93
|
|
|
public function getClientId() |
94
|
|
|
{ |
95
|
|
|
return $this->clientId; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param string|null $clientId |
100
|
|
|
*/ |
101
|
|
|
public function setClientId($clientId) |
102
|
|
|
{ |
103
|
|
|
$this->clientId = $clientId; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return bool |
108
|
|
|
*/ |
109
|
|
|
public function hasChannel() |
110
|
|
|
{ |
111
|
|
|
return null !== $this->channel; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string|null |
116
|
|
|
*/ |
117
|
|
|
public function getChannel() |
118
|
|
|
{ |
119
|
|
|
return $this->channel; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param string|null $channel |
124
|
|
|
*/ |
125
|
|
|
public function setChannel($channel) |
126
|
|
|
{ |
127
|
|
|
$this->channel = $channel; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
public function render(Map $map) |
134
|
|
|
{ |
135
|
|
|
$this->getEventDispatcher()->dispatch($event = new StaticMapEvent($map), StaticMapEvents::HTML); |
|
|
|
|
136
|
|
|
|
137
|
|
|
$query = preg_replace('/(%5B[0-9]+%5D)+=/', '=', http_build_query($event->getParameters(), '', '&')); |
138
|
|
|
$url = 'https://maps.googleapis.com/maps/api/staticmap?'.$query; |
139
|
|
|
|
140
|
|
|
if ($this->hasSecret()) { |
141
|
|
|
$url = UrlSigner::sign($url, $this->secret, $this->clientId, $this->channel); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
return $url; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: