1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2013 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
7
|
|
|
* @package MShop |
8
|
|
|
* @subpackage Plugin |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\MShop\Plugin\Provider; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Abstract class for plugin provider and decorator implementations |
17
|
|
|
* |
18
|
|
|
* @package MShop |
19
|
|
|
* @subpackage Plugin |
20
|
|
|
*/ |
21
|
|
|
abstract class Base |
22
|
|
|
{ |
23
|
|
|
private $item; |
24
|
|
|
private $context; |
25
|
|
|
private $object; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Initializes the plugin instance. |
30
|
|
|
* |
31
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object with required objects |
32
|
|
|
* @param \Aimeos\MShop\Plugin\Item\Iface $item Plugin item object |
33
|
|
|
*/ |
34
|
|
|
public function __construct( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Plugin\Item\Iface $item ) |
35
|
|
|
{ |
36
|
|
|
$this->item = $item; |
37
|
|
|
$this->context = $context; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Injects the outer object into the decorator stack |
43
|
|
|
* |
44
|
|
|
* @param \Aimeos\MShop\Plugin\Provider\Iface $object First object of the decorator stack |
45
|
|
|
* @return \Aimeos\MShop\Plugin\Provider\Iface Plugin object for chaining method calls |
|
|
|
|
46
|
|
|
*/ |
47
|
|
|
public function setObject( \Aimeos\MShop\Plugin\Provider\Iface $object ) |
48
|
|
|
{ |
49
|
|
|
$this->object = $object; |
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns the first object of the decorator stack |
56
|
|
|
* |
57
|
|
|
* @return \Aimeos\MShop\Plugin\Provider\Iface First object of the decorator stack |
58
|
|
|
*/ |
59
|
|
|
protected function getObject() |
60
|
|
|
{ |
61
|
|
|
if( $this->object !== null ) { |
62
|
|
|
return $this->object; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Returns the plugin item the provider is configured with. |
71
|
|
|
* |
72
|
|
|
* @return \Aimeos\MShop\Plugin\Item\Iface Plugin item object |
73
|
|
|
*/ |
74
|
|
|
protected function getItemBase() |
75
|
|
|
{ |
76
|
|
|
return $this->item; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Returns the configuration value from the service item specified by its key. |
82
|
|
|
* |
83
|
|
|
* @param string $key Configuration key |
84
|
|
|
* @param mixed $default Default value if configuration key isn't available |
85
|
|
|
* @return string|null Value from service item configuration |
86
|
|
|
*/ |
87
|
|
|
protected function getConfigValue( $key, $default = null ) |
88
|
|
|
{ |
89
|
|
|
$config = $this->item->getConfig(); |
90
|
|
|
|
91
|
|
|
if( isset( $config[$key] ) ) { |
92
|
|
|
return $config[$key]; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $default; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Returns the context object. |
101
|
|
|
* |
102
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Context item object |
103
|
|
|
*/ |
104
|
|
|
protected function getContext() |
105
|
|
|
{ |
106
|
|
|
return $this->context; |
107
|
|
|
} |
108
|
|
|
} |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.