1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @fabfuel <[email protected]> |
4
|
|
|
* @created 07.12.14, 13:43 |
5
|
|
|
*/ |
6
|
|
|
namespace Fabfuel\Prophiler\Decorator\PDO; |
7
|
|
|
|
8
|
|
|
use Fabfuel\Prophiler\ProfilerInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class PDOStatement |
12
|
|
|
* @package Fabfuel\Prophiler\Adapter\PDO |
13
|
|
|
* @pattern decorator |
14
|
|
|
* @mixin \PDOStatement |
15
|
|
|
*/ |
16
|
|
|
class PDOStatement |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var \PDOStatement |
20
|
|
|
*/ |
21
|
|
|
protected $statement; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var ProfilerInterface |
25
|
|
|
*/ |
26
|
|
|
protected $profiler; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
protected $parameters = []; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param \PDOStatement $statement |
35
|
|
|
* @param ProfilerInterface $profiler |
36
|
|
|
*/ |
37
|
1 |
|
public function __construct(\PDOStatement $statement, ProfilerInterface $profiler) |
38
|
|
|
{ |
39
|
1 |
|
$this->setStatement($statement); |
40
|
1 |
|
$this->setProfiler($profiler); |
41
|
1 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string $name |
45
|
|
|
* @param array $arguments |
46
|
|
|
* @return mixed |
47
|
|
|
*/ |
48
|
1 |
|
public function __call($name, array $arguments) |
49
|
|
|
{ |
50
|
1 |
|
return call_user_func_array([$this->getStatement(), $name], $arguments); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param array $input_parameters |
55
|
|
|
* @return bool |
56
|
|
|
*/ |
57
|
1 |
|
public function execute(array $input_parameters = null) |
58
|
|
|
{ |
59
|
|
|
$metadata = [ |
60
|
1 |
|
'input parameters' => $input_parameters, |
61
|
1 |
|
'bound parameters' => $this->parameters, |
62
|
1 |
|
'query' => $this->getStatement()->queryString |
63
|
1 |
|
]; |
64
|
1 |
|
$benchmark = $this->getProfiler()->start('PDOStatement::execute', $metadata, 'Database'); |
65
|
1 |
|
$result = $this->getStatement()->execute($input_parameters); |
66
|
1 |
|
$this->getProfiler()->stop($benchmark); |
67
|
1 |
|
return $result; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param mixed $parameter |
73
|
|
|
* @param mixed $variable |
74
|
|
|
* @param int $data_type [optional] |
75
|
|
|
* @param int $length [optional] |
76
|
|
|
* @param mixed $driver_options [optional] |
77
|
|
|
* @return bool |
78
|
|
|
*/ |
79
|
2 |
|
public function bindParam($parameter, &$variable, $data_type = \PDO::PARAM_STR, $length = null, $driver_options = null) |
80
|
|
|
{ |
81
|
2 |
|
$this->parameters[$parameter] = $variable; |
82
|
|
|
|
83
|
2 |
|
return $this->getStatement()->bindParam($parameter, $variable, $data_type, $length, $driver_options); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param mixed $column |
88
|
|
|
* @param mixed $param |
89
|
|
|
* @param int $type [optional] |
90
|
|
|
* @param int $maxlen [optional] |
91
|
|
|
* @param mixed $driverdata [optional] |
92
|
|
|
* @return bool |
93
|
|
|
*/ |
94
|
1 |
|
public function bindColumn($column, &$param, $type = null, $maxlen = null, $driverdata = null) |
95
|
|
|
{ |
96
|
1 |
|
return $this->getStatement()->bindColumn($column, $param, $type, $maxlen, $driverdata); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return \PDOStatement |
101
|
|
|
*/ |
102
|
1 |
|
public function getStatement() |
103
|
|
|
{ |
104
|
1 |
|
return $this->statement; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param \PDOStatement $statement |
109
|
|
|
*/ |
110
|
1 |
|
public function setStatement(\PDOStatement $statement) |
111
|
|
|
{ |
112
|
1 |
|
$this->statement = $statement; |
113
|
1 |
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return ProfilerInterface |
117
|
|
|
*/ |
118
|
1 |
|
public function getProfiler() |
119
|
|
|
{ |
120
|
1 |
|
return $this->profiler; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param ProfilerInterface $profiler |
125
|
|
|
*/ |
126
|
1 |
|
public function setProfiler(ProfilerInterface $profiler) |
127
|
|
|
{ |
128
|
1 |
|
$this->profiler = $profiler; |
129
|
1 |
|
} |
130
|
|
|
} |
131
|
|
|
|