1
|
|
|
<?php |
2
|
|
|
namespace Kir\FakePDO; |
3
|
|
|
|
4
|
|
|
use Kir\FakePDO\EventHandlers\EventHandler; |
5
|
|
|
use Kir\FakePDO\EventHandlers\EventHandlerTrait; |
6
|
|
|
use Kir\FakePDO\Tools\MethodNameGenerator; |
7
|
|
|
use PDO; |
8
|
|
|
use PDOStatement; |
9
|
|
|
|
10
|
|
|
class FakePDOStatement extends PDOStatement { |
11
|
|
|
use EventHandlerTrait; |
12
|
|
|
|
13
|
|
|
/** @var array */ |
14
|
|
|
private $attributes = null; |
15
|
|
|
/** @var MethodNameGenerator */ |
16
|
|
|
private $methodNameGenerator = null; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param EventHandler $eventHandler |
20
|
|
|
*/ |
21
|
|
|
public function __construct(EventHandler $eventHandler = null) { |
22
|
|
|
$this->setEventHandler($eventHandler); |
23
|
|
|
$this->methodNameGenerator = new MethodNameGenerator('PDOStatement'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param array|null $bound_input_params |
28
|
|
|
* @return bool |
29
|
|
|
*/ |
30
|
|
|
public function execute($bound_input_params = NULL) { |
31
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
32
|
|
|
return $this->invokeEventHandler($methodName, array($bound_input_params), function () { |
33
|
|
|
return true; |
34
|
|
|
}); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param int|null $fetch_style |
39
|
|
|
* @param int $cursor_orientation |
40
|
|
|
* @param int $cursor_offset |
41
|
|
|
* @return mixed |
42
|
|
|
*/ |
43
|
|
|
public function fetch($fetch_style = null, $cursor_orientation = PDO::FETCH_ORI_NEXT, $cursor_offset = 0) { |
44
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
45
|
|
|
return $this->invokeEventHandler($methodName, array($fetch_style, $cursor_orientation, $cursor_offset), function () { |
46
|
|
|
return []; |
47
|
|
|
}); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param mixed $parameter |
52
|
|
|
* @param mixed $variable |
53
|
|
|
* @param int $data_type |
54
|
|
|
* @param int|null $length |
55
|
|
|
* @param int|null $driver_options |
56
|
|
|
* @return bool|mixed |
57
|
|
|
*/ |
58
|
|
|
public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $length = null, $driver_options = null) { |
59
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
60
|
|
|
return $this->invokeEventHandler($methodName, array($parameter, $variable, $data_type, $driver_options), function () { |
61
|
|
|
return true; |
62
|
|
|
}); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param mixed $column |
67
|
|
|
* @param mixed $param |
68
|
|
|
* @param int $type |
69
|
|
|
* @param int $maxlen |
70
|
|
|
* @param mixed $driverdata |
71
|
|
|
* @return bool|void |
72
|
|
|
*/ |
73
|
|
|
public function bindColumn($column, &$param, $type = null, $maxlen = null, $driverdata = null) { |
74
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
75
|
|
|
return $this->invokeEventHandler($methodName, array($column, $param, $type, $maxlen, $driverdata), function () { |
76
|
|
|
return true; |
77
|
|
|
}); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param mixed $parameter |
82
|
|
|
* @param mixed $value |
83
|
|
|
* @param int $data_type |
84
|
|
|
* @return bool|mixed |
85
|
|
|
*/ |
86
|
|
|
public function bindValue($parameter, $value, $data_type = PDO::PARAM_STR) { |
87
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
88
|
|
|
return $this->invokeEventHandler($methodName, array($parameter, $value, $data_type), function () { |
89
|
|
|
return true; |
90
|
|
|
}); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return int |
95
|
|
|
*/ |
96
|
|
|
public function rowCount() { |
97
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
98
|
|
|
return $this->invokeEventHandler($methodName, array(), function () { |
99
|
|
|
return 0; |
100
|
|
|
}); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param int $column_number |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
|
|
public function fetchColumn($column_number = 0) { |
108
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
109
|
|
|
return $this->invokeEventHandler($methodName, array(), function () { |
110
|
|
|
return ''; |
111
|
|
|
}); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param mixed|null $how |
|
|
|
|
116
|
|
|
* @param mixed|null $class_name |
|
|
|
|
117
|
|
|
* @param array|null $ctor_args |
|
|
|
|
118
|
|
|
* @return array |
119
|
|
|
*/ |
120
|
|
|
public function fetchAll(int $mode = PDO::FETCH_BOTH, mixed ...$args) { |
121
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
122
|
|
|
return $this->invokeEventHandler($methodName, array(), function () { |
123
|
|
|
return []; |
124
|
|
|
}); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param string $class_name |
129
|
|
|
* @param array $ctor_args |
130
|
|
|
* @return mixed |
131
|
|
|
*/ |
132
|
|
|
public function fetchObject($class_name = NULL, $ctor_args = NULL) { |
133
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
134
|
|
|
return $this->invokeEventHandler($methodName, array(), function () { |
135
|
|
|
return new \stdClass(); |
136
|
|
|
}); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return string |
141
|
|
|
*/ |
142
|
|
|
public function errorCode() { |
143
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
144
|
|
|
return $this->invokeEventHandler($methodName, array(), function () { |
145
|
|
|
return ''; |
146
|
|
|
}); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return array |
151
|
|
|
*/ |
152
|
|
|
public function errorInfo() { |
153
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
154
|
|
|
return $this->invokeEventHandler($methodName, array(), function () { |
155
|
|
|
return [0, 0, 0]; |
156
|
|
|
}); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param int $attribute |
161
|
|
|
* @return mixed |
162
|
|
|
*/ |
163
|
|
|
public function getAttribute($attribute) { |
164
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
165
|
|
|
return $this->invokeEventHandler($methodName, array($attribute), function ($attribute) { |
166
|
|
|
$attribute = json_encode($attribute); |
167
|
|
|
if(array_key_exists($attribute, $this->attributes)) { |
168
|
|
|
return $this->attributes[$attribute]; |
169
|
|
|
} |
170
|
|
|
return null; |
171
|
|
|
}); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param int $attribute |
176
|
|
|
* @param mixed $value |
177
|
|
|
* @return bool |
178
|
|
|
*/ |
179
|
|
|
public function setAttribute($attribute, $value) { |
180
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
181
|
|
|
return $this->invokeEventHandler($methodName, array($attribute, $value), function ($attribute, $value) { |
182
|
|
|
$attribute = json_encode($attribute); |
183
|
|
|
$this->attributes[$attribute] = $value; |
184
|
|
|
return true; |
185
|
|
|
}); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* |
190
|
|
|
*/ |
191
|
|
|
public function columnCount() { |
192
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
193
|
|
|
return $this->invokeEventHandler($methodName, array(), function () { |
194
|
|
|
return 0; |
195
|
|
|
}); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param int $column |
200
|
|
|
* @return array |
201
|
|
|
*/ |
202
|
|
|
public function getColumnMeta($column) { |
203
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
204
|
|
|
return $this->invokeEventHandler($methodName, array($column), function () { |
205
|
|
|
return []; |
206
|
|
|
}); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @param int $mode |
211
|
|
|
* @param array|null $params |
|
|
|
|
212
|
|
|
* @return bool |
213
|
|
|
*/ |
214
|
|
|
public function setFetchMode(int $mode, ...$args) { |
215
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
216
|
|
|
return $this->invokeEventHandler($methodName, array($mode), function () { |
217
|
|
|
return true; |
218
|
|
|
}); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @return bool |
223
|
|
|
*/ |
224
|
|
|
public function nextRowset() { |
225
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
226
|
|
|
return $this->invokeEventHandler($methodName, array(), function () { |
227
|
|
|
return true; |
228
|
|
|
}); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @return bool |
233
|
|
|
*/ |
234
|
|
|
public function closeCursor() { |
235
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
236
|
|
|
return $this->invokeEventHandler($methodName, array(), function () { |
237
|
|
|
return true; |
238
|
|
|
}); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @return bool |
243
|
|
|
*/ |
244
|
|
|
public function debugDumpParams() { |
245
|
|
|
$methodName = $this->methodNameGenerator->getQualifiedMethodName(__FUNCTION__); |
246
|
|
|
return $this->invokeEventHandler($methodName, array(), function () { |
247
|
|
|
return true; |
248
|
|
|
}); |
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.