1 | <?php |
||
5 | abstract class ItemWrapper extends BundleItem |
||
6 | { |
||
7 | /** |
||
8 | * Target: 'key', 'value' or 'both'. |
||
9 | * |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $target; |
||
13 | |||
14 | /** |
||
15 | * Any parameters needed for the effect. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $wrapperParameters = []; |
||
20 | |||
21 | /** |
||
22 | * Construct. |
||
23 | * |
||
24 | * @param string $id |
||
25 | * @param string $target |
||
26 | * @param array $wrapperParameters |
||
27 | */ |
||
28 | public function __construct($id, $target = null, array $wrapperParameters = []) |
||
29 | { |
||
30 | parent::__construct($id); |
||
31 | |||
32 | $this->target = $target; |
||
33 | |||
34 | $this->wrapperParameters = $wrapperParameters; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Get the set target. |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | public function getAffect() |
||
43 | { |
||
44 | return $this->target; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * If target is key, get key from child. Otherwise, get from parent. |
||
49 | * |
||
50 | * @return string |
||
51 | */ |
||
52 | public function getKey() |
||
53 | { |
||
54 | if ($this->target === 'key' || $this->target === 'both') { |
||
55 | return $this->key($this->key); |
||
56 | } |
||
57 | |||
58 | return parent::getKey(); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * If target is value, get value from child. Otherwise, get from parent. |
||
63 | * |
||
64 | * @return mixed |
||
65 | */ |
||
66 | public function getValue() |
||
67 | { |
||
68 | if ($this->target === 'value' || $this->target === 'both') { |
||
69 | return $this->value($this->value); |
||
70 | } |
||
71 | |||
72 | return parent::getValue(); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Alter key and return. |
||
77 | * |
||
78 | * @param string $key |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | abstract public function key($key); |
||
83 | |||
84 | /** |
||
85 | * Alter value and return. |
||
86 | * |
||
87 | * @param mixed $value |
||
88 | * |
||
89 | * @return mixed |
||
90 | */ |
||
91 | abstract public function value($value); |
||
92 | } |
||
93 |