|
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\Renderer\Utility; |
|
13
|
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Helper\Renderer\AbstractRenderer; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author GeLo <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
class RequirementLoaderRenderer extends AbstractRenderer |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @param string $name |
|
23
|
|
|
* @param string|null $intervalVariable |
|
24
|
|
|
* @param string|null $callbackVariable |
|
25
|
|
|
* @param string|null $requirementVariable |
|
26
|
|
|
* @param int $interval |
|
27
|
|
|
* @param bool $newLine |
|
28
|
|
|
* |
|
29
|
|
|
* @return string |
|
30
|
|
|
*/ |
|
31
|
280 |
|
public function render( |
|
32
|
|
|
$name, |
|
33
|
|
|
$intervalVariable = null, |
|
34
|
|
|
$callbackVariable = null, |
|
35
|
|
|
$requirementVariable = null, |
|
36
|
|
|
$interval = 10, |
|
37
|
|
|
$newLine = true |
|
38
|
|
|
) { |
|
39
|
280 |
|
$formatter = $this->getFormatter(); |
|
40
|
|
|
|
|
41
|
280 |
|
$intervalVariable = $intervalVariable ?: 'i'; |
|
42
|
280 |
|
$callbackVariable = $callbackVariable ?: 'c'; |
|
43
|
280 |
|
$requirementVariable = $requirementVariable ?: 'r'; |
|
44
|
|
|
|
|
45
|
280 |
|
return $formatter->renderClosure($this->renderRequirement( |
|
46
|
210 |
|
$intervalVariable, |
|
47
|
210 |
|
$callbackVariable, |
|
48
|
210 |
|
$requirementVariable, |
|
49
|
280 |
|
$formatter->renderStatement('else', $formatter->renderAssignment( |
|
50
|
280 |
|
'var '.$intervalVariable, |
|
51
|
280 |
|
$formatter->renderCall('setInterval', [ |
|
52
|
280 |
|
$formatter->renderClosure($this->renderRequirement( |
|
53
|
210 |
|
$intervalVariable, |
|
54
|
210 |
|
$callbackVariable, |
|
55
|
70 |
|
$requirementVariable |
|
56
|
140 |
|
)), |
|
57
|
280 |
|
$interval, |
|
58
|
280 |
|
], true) |
|
59
|
280 |
|
), null, null, false) |
|
60
|
280 |
|
), [$callbackVariable, $requirementVariable], $name, true, $newLine); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param string $intervalVariable |
|
65
|
|
|
* @param string $callbackVariable |
|
66
|
|
|
* @param string $requirementVariable |
|
67
|
|
|
* @param string|null $nextStatement |
|
68
|
|
|
* |
|
69
|
|
|
* @return string |
|
70
|
|
|
*/ |
|
71
|
280 |
|
private function renderRequirement( |
|
72
|
|
|
$intervalVariable, |
|
73
|
|
|
$callbackVariable, |
|
74
|
|
|
$requirementVariable, |
|
75
|
|
|
$nextStatement = null |
|
76
|
|
|
) { |
|
77
|
280 |
|
$formatter = $this->getFormatter(); |
|
78
|
280 |
|
$codes = [$formatter->renderCall($callbackVariable, [], true)]; |
|
79
|
|
|
|
|
80
|
280 |
|
if (empty($nextStatement)) { |
|
81
|
280 |
|
array_unshift($codes, $formatter->renderCall('clearInterval', [$intervalVariable], true)); |
|
82
|
140 |
|
} |
|
83
|
|
|
|
|
84
|
280 |
|
return $formatter->renderStatement( |
|
85
|
280 |
|
'if', |
|
86
|
280 |
|
$formatter->renderLines($codes, true, false), |
|
87
|
280 |
|
$formatter->renderCall($requirementVariable), |
|
88
|
210 |
|
$nextStatement, |
|
89
|
140 |
|
false |
|
90
|
140 |
|
); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|