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