forked from ddeboer/GoogleBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoogleExtension.php
executable file
·110 lines (98 loc) · 3.75 KB
/
GoogleExtension.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
99
100
101
102
103
104
105
106
107
108
109
110
<?php
namespace AntiMattr\GoogleBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
class GoogleExtension extends Extension
{
/**
* @see Symfony\Component\DependencyInjection\Extension.ExtensionInterface::load()
*/
public function load(array $configs, ContainerBuilder $container)
{
$modules = array(
'adwords' => array(),
'analytics' => array(),
'maps' => array(),
);
foreach ($configs as $config) {
foreach (array_keys($modules) as $module) {
if (array_key_exists($module, $config)) {
$modules[$module][] = isset($config[$module]) ? $config[$module] : array();
}
}
}
foreach (array_keys($modules) as $module) {
if (!empty($modules[$module])) {
call_user_func(array($this, $module . 'Load'), $modules[$module], $container);
}
}
}
/**
* @param array $configs
* @param ContainerBuilder $container
*/
private function adwordsLoad(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('adwords.xml');
foreach ($configs as $config) {
if (isset($config['conversions'])) {
$container->setParameter('google.adwords.conversions', $config['conversions']);
}
}
}
/**
* @param array $configs
* @param ContainerBuilder $container
*/
private function analyticsLoad(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('analytics.xml');
foreach ($configs as $config) {
if (isset($config['trackers'])) {
$container->setParameter('google.analytics.trackers', $config['trackers']);
}
if (isset($config['dashboard'])) {
$container->setParameter('google.analytics.dashboard', $config['dashboard']);
}
if (isset($config['whitelist'])) {
$container->setParameter('google.analytics.whitelist', $config['whitelist']);
}
if (isset($config['js_source_https'])) {
$container->setParameter('google.analytics.js_source_https', $config['js_source_https']);
}
if (isset($config['js_source_http'])) {
$container->setParameter('google.analytics.js_source_http', $config['js_source_http']);
}
if (isset($config['js_source_endpoint'])) {
$container->setParameter('google.analytics.js_source_endpoint', $config['js_source_endpoint']);
}
}
}
/**
* @param array $configs
* @param ContainerBuilder $container
*/
private function mapsLoad(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('maps.xml');
foreach ($configs as $config) {
if (isset($config['config'])) {
$container->setParameter('google.maps.config', $config['config']);
}
}
}
/**
* @see Symfony\Component\DependencyInjection\Extension.ExtensionInterface::getAlias()
* @codeCoverageIgnore
*/
public function getAlias()
{
return 'google';
}
}