1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the GoogleTagManagerBundle project |
4
|
|
|
* |
5
|
|
|
* (c) Philipp Braeutigam <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Xynnn\GoogleTagManagerBundle\Service; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class GoogleTagManager |
15
|
|
|
* |
16
|
|
|
* @package Xynnn\GoogleTagManagerBundle\Service |
17
|
|
|
*/ |
18
|
|
|
class GoogleTagManager implements GoogleTagManagerInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var bool |
22
|
|
|
*/ |
23
|
|
|
private $enabled; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $id; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
private $data = array(); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
private $push = array(); |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param $enabled |
42
|
|
|
* @param $id |
43
|
|
|
*/ |
44
|
|
|
public function __construct($enabled, $id) |
45
|
|
|
{ |
46
|
|
|
$this->enabled = (bool)$enabled; |
47
|
|
|
$this->id = $id; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function addData($key, $value) |
54
|
|
|
{ |
55
|
|
|
$this->setData($key, $value); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
public function setData($key, $value) |
62
|
|
|
{ |
63
|
|
|
$this->data[$key] = $value; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
|
|
public function mergeData($key, $value) |
70
|
|
|
{ |
71
|
|
|
$merge = array(); |
72
|
|
|
if (array_key_exists($key, $this->data)) { |
73
|
|
|
$merge = $this->data[$key]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$this->setData($key, array_merge_recursive($merge, $value)); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritdoc} |
81
|
|
|
*/ |
82
|
|
|
public function isEnabled() |
83
|
|
|
{ |
84
|
|
|
return $this->enabled; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritdoc} |
89
|
|
|
*/ |
90
|
|
|
public function getId() |
91
|
|
|
{ |
92
|
|
|
return $this->id; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* {@inheritdoc} |
97
|
|
|
*/ |
98
|
|
|
public function getData() |
99
|
|
|
{ |
100
|
|
|
return $this->data; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* {@inheritdoc} |
105
|
|
|
*/ |
106
|
|
|
public function addPush($value) |
107
|
|
|
{ |
108
|
|
|
$this->push[] = $value; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* {@inheritdoc} |
113
|
|
|
*/ |
114
|
|
|
public function getPush() |
115
|
|
|
{ |
116
|
|
|
return $this->push; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* {@inheritdoc} |
121
|
|
|
*/ |
122
|
|
|
public function hasData() |
123
|
|
|
{ |
124
|
|
|
return is_array($this->getData()) |
125
|
|
|
&& count($this->getData()) > 0; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|