1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dekalee\AdbackAnalyticsBundle\Twig; |
4
|
|
|
|
5
|
|
|
use Dekalee\AdbackAnalytics\Generator\AnalyticsScriptGenerator; |
6
|
|
|
use Dekalee\AdbackAnalytics\Generator\MessageScriptGenerator; |
7
|
|
|
use Dekalee\AdbackAnalytics\Generator\AutopromoBannerScriptGenerator; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class ScriptExtension |
11
|
|
|
*/ |
12
|
|
|
class ScriptExtension extends \Twig_Extension |
13
|
|
|
{ |
14
|
|
|
protected $analyticsGenerator; |
15
|
|
|
protected $messageGenerator; |
16
|
|
|
protected $autopromoBannerGenerator; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param AnalyticsScriptGenerator $analyticsScriptGenerator |
20
|
|
|
* @param MessageScriptGenerator $messageScriptGenerator |
21
|
|
|
* @param AutopromoBannerScriptGenerator $autopromoBannerScriptGenerator |
22
|
|
|
*/ |
23
|
|
|
public function __construct(AnalyticsScriptGenerator $analyticsScriptGenerator, MessageScriptGenerator $messageScriptGenerator, AutopromoBannerScriptGenerator $autopromoBannerScriptGenerator) |
24
|
|
|
{ |
25
|
|
|
$this->analyticsGenerator = $analyticsScriptGenerator; |
26
|
|
|
$this->messageGenerator = $messageScriptGenerator; |
27
|
|
|
$this->autopromoBannerGenerator = $autopromoBannerScriptGenerator; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return string |
32
|
|
|
*/ |
33
|
|
|
public function generateScripts() |
34
|
|
|
{ |
35
|
|
|
return sprintf('<script>%s</script><script>%s</script>', |
36
|
|
|
$this->analyticsGenerator->generate(), |
37
|
|
|
$this->messageGenerator->generate() |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
public function generateAutopromoBannerScript() |
45
|
|
|
{ |
46
|
|
|
return sprintf('<script>%s</script>', $this->autopromoBannerGenerator->generate()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function getFunctions() |
53
|
|
|
{ |
54
|
|
|
return [ |
55
|
|
|
new \Twig_SimpleFunction('adback_generate_scripts', [$this, 'generateScripts'], ['is_safe' => ['html']]), |
56
|
|
|
new \Twig_SimpleFunction('adback_generate_autopromo_banner_script', [$this, 'generateAutopromoBannerScript'], ['is_safe' => ['html']]), |
57
|
|
|
]; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|