|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Iris\SaleWrapper; |
|
4
|
|
|
|
|
5
|
|
|
abstract class Base |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var \Iris\Manager |
|
9
|
|
|
*/ |
|
10
|
|
|
private $manager; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var \Iris\Mapping\Order |
|
14
|
|
|
*/ |
|
15
|
|
|
private $orderMapping; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @param \Iris\Manager $manager |
|
19
|
|
|
*/ |
|
20
|
31 |
|
public function __construct(\Iris\Manager $manager) |
|
21
|
|
|
{ |
|
22
|
31 |
|
$this->manager = $manager; |
|
23
|
31 |
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @return \Iris\Interfaces\Order |
|
27
|
|
|
*/ |
|
28
|
12 |
|
public function getOrderService() |
|
29
|
|
|
{ |
|
30
|
12 |
|
return $this->getManager()->getService(\Iris\Factory::ORDER); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return \Iris\Api\PartnerClient |
|
35
|
|
|
*/ |
|
36
|
4 |
|
public function getPartnerApiClient() |
|
37
|
|
|
{ |
|
38
|
4 |
|
return $this->getManager()->getPartnerApiClient(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return \Iris\Api\VentureClient |
|
43
|
|
|
*/ |
|
44
|
8 |
|
public function getVentureApiClient() |
|
45
|
|
|
{ |
|
46
|
8 |
|
return $this->getManager()->getVentureApiClient(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return \Iris\Manager |
|
51
|
|
|
*/ |
|
52
|
30 |
|
public function getManager() |
|
53
|
|
|
{ |
|
54
|
30 |
|
return $this->manager; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Check if method exists in current context. |
|
59
|
|
|
* @param string $methodName |
|
60
|
|
|
* @return bool |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function canCall($methodName) |
|
63
|
|
|
{ |
|
64
|
|
|
if (!method_exists($this, $methodName)) { |
|
65
|
|
|
throw new \Iris\Exceptions\MethodNotAllowed($methodName, $this->getName()); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
return true; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param string $methodName |
|
72
|
|
|
* @param array $data |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
|
|
final public function call($methodName, array $data = array()) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->canCall($methodName); |
|
78
|
|
|
|
|
79
|
|
|
$ref = new \ReflectionObject($this); |
|
80
|
|
|
$method = $ref->getMethod($methodName); |
|
81
|
|
|
|
|
82
|
|
|
$args = $this->mappingArguments($method, $data); |
|
83
|
|
|
|
|
84
|
|
|
return $method->invokeArgs($this, $args); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param \ReflectionMethod $method |
|
89
|
|
|
* @param array $data |
|
90
|
|
|
* @return array |
|
91
|
|
|
* @throws \Iris\Exceptions\ParameterNotFound |
|
92
|
|
|
*/ |
|
93
|
|
|
final protected function mappingArguments(\ReflectionMethod $method, array $data) |
|
94
|
|
|
{ |
|
95
|
|
|
$parameters = $method->getParameters(); |
|
96
|
|
|
$args = []; |
|
97
|
|
|
foreach ($parameters as $parameter) { |
|
98
|
|
|
$parameterName = mb_strtolower(preg_replace('/([A-Z])/', '_\1', $parameter->name)); |
|
99
|
|
|
$this->validateArgument($parameterName, $method, $data); |
|
100
|
|
|
$args[$parameter->name] = $data[$parameterName]; |
|
101
|
|
|
} |
|
102
|
|
|
return $args; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param $parameterName |
|
107
|
|
|
* @param \ReflectionMethod $method |
|
108
|
|
|
* @param $data |
|
109
|
|
|
* @return void |
|
110
|
|
|
* @throws \Iris\Exceptions\ParameterNotFound |
|
111
|
|
|
*/ |
|
112
|
|
|
final protected function validateArgument($parameterName, \ReflectionMethod $method, $data) |
|
113
|
|
|
{ |
|
114
|
|
|
if (!isset($data[$parameterName])) { |
|
115
|
|
|
throw new \Iris\Exceptions\ParameterNotFound($parameterName, $method->name); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return \Iris\Mapping\Order |
|
121
|
|
|
*/ |
|
122
|
3 |
|
public function getOrderMapping() |
|
123
|
|
|
{ |
|
124
|
3 |
|
$this->orderMapping || $this->setOrderMapping(\Iris\Mapping\Order::getInstance()); |
|
125
|
3 |
|
return $this->orderMapping; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param \Iris\Mapping\Order $map |
|
130
|
|
|
* @return \Iris\SaleWrapper\Venture |
|
131
|
|
|
*/ |
|
132
|
3 |
|
public function setOrderMapping(\Iris\Mapping\Order $map) |
|
133
|
|
|
{ |
|
134
|
3 |
|
$this->orderMapping = $map; |
|
135
|
3 |
|
return $this; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.