1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TheIconic\Tracking\GoogleAnalytics\Parameters; |
4
|
|
|
|
5
|
|
|
use TheIconic\Tracking\GoogleAnalytics\Traits\Indexable; |
6
|
|
|
use IteratorAggregate; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class CompoundParameterCollection |
10
|
|
|
* |
11
|
|
|
* Contains a set of compound parameters. The name of the collection is prepend before the compound parameter |
12
|
|
|
* names. The name can be indexed by the placeholder as specified in the Indexable trait. |
13
|
|
|
* |
14
|
|
|
* @package TheIconic\Tracking\GoogleAnalytics\Parameters |
15
|
|
|
*/ |
16
|
|
|
abstract class CompoundParameterCollection implements IteratorAggregate |
17
|
|
|
{ |
18
|
|
|
use Indexable; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Name for the collection of compound parameters. Its prepend to the payload names |
22
|
|
|
* of the compound parameter. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $name = ''; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Holds all the compound parameters that belong to the collection. |
30
|
|
|
* |
31
|
|
|
* @var CompoundParameter[] |
32
|
|
|
*/ |
33
|
|
|
protected $items = []; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Indexes the name in case it has a placeholder. |
37
|
|
|
* |
38
|
|
|
* @param string $index |
39
|
|
|
*/ |
40
|
|
|
public function __construct($index = '') |
41
|
|
|
{ |
42
|
|
|
$this->name = $this->addIndex($this->name, $index); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @inheritDoc |
47
|
|
|
*/ |
48
|
|
|
public function add(CompoundParameter $compoundParameter) |
49
|
|
|
{ |
50
|
|
|
$this->items[] = $compoundParameter; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @inheritDoc |
55
|
|
|
*/ |
56
|
|
|
public function getParametersArray() |
57
|
|
|
{ |
58
|
|
|
$parameters = []; |
59
|
|
|
|
60
|
|
|
foreach ($this as $number => $compoundParameter) { |
61
|
|
|
$currentParameters = []; |
62
|
|
|
|
63
|
|
|
foreach ($compoundParameter->getParameters() as $name => $value) { |
64
|
|
|
$currentParameters[$this->name . ($number + 1) . $name] = $value; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$parameters = array_merge($parameters, $currentParameters); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $parameters; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Gets the human readable items for the parameter. |
75
|
|
|
* |
76
|
|
|
* @return Array |
77
|
|
|
*/ |
78
|
|
|
public function getReadableItems() |
79
|
|
|
{ |
80
|
|
|
$readablesItems = array(); |
81
|
|
|
foreach ($this->items as $key => $item) { |
82
|
|
|
array_push($readablesItems, $item->getReadableParameters()); |
83
|
|
|
} |
84
|
|
|
return $readablesItems; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @inheritDoc |
89
|
|
|
*/ |
90
|
|
|
public function getIterator() |
91
|
|
|
{ |
92
|
|
|
return new \ArrayIterator($this->items); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|