1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ez\DbLinker\Driver\Connection; |
4
|
|
|
|
5
|
|
|
use IteratorAggregate; |
6
|
|
|
use Doctrine\DBAL\Driver\Statement; |
7
|
|
|
use Ez\DbLinker\RetryStrategy; |
8
|
|
|
|
9
|
|
|
class RetryStatement implements IteratorAggregate, Statement |
10
|
|
|
{ |
11
|
|
|
private $statement; |
12
|
|
|
private $retryConnection; |
13
|
|
|
private $retryStrategy; |
14
|
|
|
|
15
|
|
|
use CallAndRetry; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param Statement $statement |
19
|
|
|
*/ |
20
|
|
|
public function __construct(Statement $statement, RetryConnection $retryConnection, RetryStrategy $retryStrategy) |
21
|
|
|
{ |
22
|
|
|
$this->statement = $statement; |
23
|
|
|
$this->retryConnection = $retryConnection; |
24
|
|
|
$this->retryStrategy = $retryStrategy; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
public function execute($params = NULL) |
31
|
|
|
{ |
32
|
|
|
return (bool)$this->callAndRetry(function () use ($params) { |
33
|
|
|
return $this->statement->execute($params); |
|
|
|
|
34
|
|
|
}, $this->retryStrategy, $this->retryConnection); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function bindParam($column, &$variable, $type = null, $length = null) |
41
|
|
|
{ |
42
|
|
|
return $this->statement->bindParam($column, $variable, $type, $length); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
public function bindValue($param, $value, $type = null) |
49
|
|
|
{ |
50
|
|
|
return $this->statement->bindValue($param, $value, $type); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) |
57
|
|
|
{ |
58
|
|
|
return $this->statement->fetch($fetchMode, $cursorOrientation, $cursorOffset); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) |
65
|
|
|
{ |
66
|
|
|
return $this->statement->fetchAll($fetchMode, $fetchArgument, $ctorArgs); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
|
|
public function fetchColumn($columnIndex = 0) |
73
|
|
|
{ |
74
|
|
|
return $this->statement->fetchColumn($columnIndex); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritdoc} |
79
|
|
|
*/ |
80
|
|
|
public function errorCode() |
81
|
|
|
{ |
82
|
|
|
return $this->statement->errorCode(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
|
|
public function errorInfo() |
89
|
|
|
{ |
90
|
|
|
return $this->statement->errorInfo(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritdoc} |
95
|
|
|
*/ |
96
|
|
|
public function closeCursor() |
97
|
|
|
{ |
98
|
|
|
return $this->statement->closeCursor(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* {@inheritdoc} |
103
|
|
|
*/ |
104
|
|
|
public function rowCount() |
105
|
|
|
{ |
106
|
|
|
return $this->statement->rowCount(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* {@inheritdoc} |
111
|
|
|
*/ |
112
|
|
|
public function columnCount() |
113
|
|
|
{ |
114
|
|
|
return $this->statement->columnCount(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* {@inheritdoc} |
119
|
|
|
*/ |
120
|
|
|
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) |
121
|
|
|
{ |
122
|
|
|
return $this->statement->setFetchMode($fetchMode, $arg2, $arg3); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* {@inheritdoc} |
127
|
|
|
*/ |
128
|
|
|
public function getIterator() |
129
|
|
|
{ |
130
|
|
|
return $this->statement; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.