1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WebStream\Database\Driver; |
4
|
|
|
|
5
|
|
|
use WebStream\DI\Injector; |
|
|
|
|
6
|
|
|
use WebStream\Container\Container; |
|
|
|
|
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* DatabaseDriver |
10
|
|
|
* @author Ryuichi TANAKA. |
11
|
|
|
* @since 2013/12/07 |
12
|
|
|
* @version 0.4 |
13
|
|
|
*/ |
14
|
|
|
abstract class DatabaseDriver |
15
|
|
|
{ |
16
|
|
|
use Injector; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var \Doctrine\DBAL\Connection DBオブジェクト |
20
|
|
|
*/ |
21
|
|
|
protected $connection; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Container DB接続設定 |
25
|
|
|
*/ |
26
|
|
|
protected $config; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* constructor |
30
|
|
|
*/ |
31
|
52 |
|
public function __construct(Container $config) |
32
|
|
|
{ |
33
|
52 |
|
$this->config = $config; |
34
|
52 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* destructor |
38
|
|
|
*/ |
39
|
|
|
public function __destruct() |
40
|
|
|
{ |
41
|
|
|
// $this->logger->debug("Release driver: " . get_class($this)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* 接続する |
46
|
|
|
*/ |
47
|
|
|
abstract public function connect(); |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* 切断する |
51
|
|
|
*/ |
52
|
52 |
|
public function disconnect() |
53
|
|
|
{ |
54
|
52 |
|
if ($this->connection !== null) { |
55
|
52 |
|
$this->logger->debug("Database disconnect."); |
56
|
52 |
|
$this->connection->close(); |
57
|
52 |
|
$this->connection = null; |
58
|
|
|
} |
59
|
52 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* トランザクションを開始する |
63
|
|
|
* @return boolean トランザクション開始結果 |
64
|
|
|
*/ |
65
|
16 |
|
public function beginTransaction() |
66
|
|
|
{ |
67
|
16 |
|
$inTransaction = false; |
68
|
16 |
|
if ($this->connection !== null) { |
69
|
16 |
|
$this->connection->beginTransaction(); |
70
|
16 |
|
$inTransaction = $this->inTransaction(); |
71
|
|
|
} |
72
|
|
|
|
73
|
16 |
|
return $inTransaction; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* コミットする |
78
|
|
|
*/ |
79
|
8 |
|
public function commit() |
80
|
|
|
{ |
81
|
8 |
|
if ($this->connection !== null) { |
82
|
8 |
|
$this->connection->commit(); |
83
|
|
|
} |
84
|
8 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* ロールバックする |
88
|
|
|
*/ |
89
|
16 |
|
public function rollback() |
90
|
|
|
{ |
91
|
16 |
|
if ($this->inTransaction()) { |
92
|
16 |
|
$this->connection->rollBack(); |
93
|
|
|
} |
94
|
16 |
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* 自動コミットフラグを設定する |
98
|
|
|
* @param bool $isAutoCommit 自動コミットフラグ |
99
|
|
|
*/ |
100
|
16 |
|
public function setAutoCommit(bool $isAutoCommit) |
101
|
|
|
{ |
102
|
16 |
|
$this->connection->setAutoCommit($isAutoCommit); |
103
|
16 |
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* DB接続されているか |
107
|
|
|
* @return bool 接続有無 |
108
|
|
|
*/ |
109
|
|
|
public function isConnected() |
110
|
|
|
{ |
111
|
|
|
return $this->connection !== null; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* トランザクション内かどうか |
116
|
|
|
* @return bool トランザクション内かどうか |
117
|
|
|
*/ |
118
|
52 |
|
public function inTransaction() |
119
|
|
|
{ |
120
|
52 |
|
return $this->connection !== null ? $this->connection->isTransactionActive() : false; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* SQLをセットしてステートメントを返却する |
125
|
|
|
* @param string SQL |
126
|
|
|
* @return \Doctrine\DBAL\Driver\DriverStatement ステートメント |
|
|
|
|
127
|
|
|
*/ |
128
|
52 |
|
public function getStatement(string $sql) |
129
|
|
|
{ |
130
|
52 |
|
return $this->connection !== null ? $this->connection->prepare($sql) : null; |
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* トランザクション分離レベルを返却する |
135
|
|
|
* @return int トランザクション分離レベル |
136
|
|
|
*/ |
137
|
|
|
public function getTransactionIsolation() |
138
|
|
|
{ |
139
|
|
|
return $this->connection->getTransactionIsolation(); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* トランザクション分離レベルを設定する |
144
|
|
|
* @param int $isolationLevel トランザクション分離レベル |
145
|
|
|
*/ |
146
|
16 |
|
public function setTransactionIsolation(int $isolationLevel) |
147
|
|
|
{ |
148
|
16 |
|
$this->connection->setTransactionIsolation($isolationLevel); |
149
|
16 |
|
} |
150
|
|
|
} |
151
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths