|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Debug; |
|
6
|
|
|
|
|
7
|
|
|
use Closure; |
|
8
|
|
|
use Yiisoft\Db\Command\CommandInterface; |
|
9
|
|
|
use Yiisoft\Db\Connection\ConnectionInterface; |
|
10
|
|
|
use Yiisoft\Db\Profiler\ProfilerInterface; |
|
11
|
|
|
use Yiisoft\Db\Query\BatchQueryResultInterface; |
|
12
|
|
|
use Yiisoft\Db\Query\QueryInterface; |
|
13
|
|
|
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; |
|
14
|
|
|
use Yiisoft\Db\Schema\QuoterInterface; |
|
15
|
|
|
use Yiisoft\Db\Schema\SchemaInterface; |
|
16
|
|
|
use Yiisoft\Db\Schema\TableSchemaInterface; |
|
17
|
|
|
use Yiisoft\Db\Transaction\TransactionInterface; |
|
18
|
|
|
|
|
19
|
|
|
final class ConnectionInterfaceProxy implements ConnectionInterface |
|
20
|
|
|
{ |
|
21
|
|
|
public function __construct( |
|
22
|
|
|
private ConnectionInterface $connection, |
|
23
|
|
|
private DatabaseCollector $collector |
|
24
|
|
|
) { |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function beginTransaction(string $isolationLevel = null): TransactionInterface |
|
28
|
|
|
{ |
|
29
|
|
|
[$callStack] = debug_backtrace(); |
|
30
|
|
|
|
|
31
|
|
|
$result = $this->connection->beginTransaction($isolationLevel); |
|
32
|
|
|
|
|
33
|
|
|
$this->collector->collectTransactionStart($isolationLevel, $callStack['file'] . ':' . $callStack['line']); |
|
34
|
|
|
return new TransactionInterfaceDecorator($result, $this->collector); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function createBatchQueryResult(QueryInterface $query, bool $each = false): BatchQueryResultInterface |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->connection->createBatchQueryResult($query, $each); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function createCommand(string $sql = null, array $params = []): CommandInterface |
|
43
|
|
|
{ |
|
44
|
|
|
return new CommandInterfaceProxy( |
|
45
|
|
|
$this->connection->createCommand($sql, $params), |
|
46
|
|
|
$this->collector, |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function createTransaction(): TransactionInterface |
|
51
|
|
|
{ |
|
52
|
|
|
return new TransactionInterfaceDecorator( |
|
53
|
|
|
$this->connection->createTransaction(), |
|
54
|
|
|
$this->collector, |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function close(): void |
|
59
|
|
|
{ |
|
60
|
|
|
$this->connection->close(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function getCacheKey(): array |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->connection->getCacheKey(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getName(): string |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->connection->getName(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function getLastInsertID(string $sequenceName = null): string |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->connection->getLastInsertID($sequenceName); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function getQueryBuilder(): QueryBuilderInterface |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->connection->getQueryBuilder(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function getQuoter(): QuoterInterface |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->connection->getQuoter(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getSchema(): SchemaInterface |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->connection->getSchema(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function getServerVersion(): string |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->connection->getServerVersion(); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function getTablePrefix(): string |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->connection->getTablePrefix(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getTableSchema(string $name, bool $refresh = false): TableSchemaInterface|null |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->connection->getTableSchema($name, $refresh); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function getTransaction(): TransactionInterface|null |
|
109
|
|
|
{ |
|
110
|
|
|
$result = $this->connection->getTransaction(); |
|
111
|
|
|
|
|
112
|
|
|
return $result === null |
|
113
|
|
|
? null |
|
114
|
|
|
: new TransactionInterfaceDecorator( |
|
115
|
|
|
$result, |
|
116
|
|
|
$this->collector, |
|
117
|
|
|
); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function isActive(): bool |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->connection->isActive(); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function isSavepointEnabled(): bool |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->connection->isSavepointEnabled(); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function open(): void |
|
131
|
|
|
{ |
|
132
|
|
|
$this->connection->open(); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function quoteValue(mixed $value): mixed |
|
136
|
|
|
{ |
|
137
|
|
|
return $this->connection->quoteValue($value); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function setEnableSavepoint(bool $value): void |
|
141
|
|
|
{ |
|
142
|
|
|
$this->connection->setEnableSavepoint($value); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function setTablePrefix(string $value): void |
|
146
|
|
|
{ |
|
147
|
|
|
$this->connection->setTablePrefix($value); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
public function transaction(Closure $closure, string $isolationLevel = null): mixed |
|
151
|
|
|
{ |
|
152
|
|
|
[$callStack] = debug_backtrace(); |
|
153
|
|
|
|
|
154
|
|
|
$this->collector->collectTransactionStart($isolationLevel, $callStack['file'] . ':' . $callStack['line']); |
|
155
|
|
|
|
|
156
|
|
|
return $this->connection->transaction(fn () => $closure($this), $isolationLevel); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public function setProfiler(?ProfilerInterface $profiler): void |
|
160
|
|
|
{ |
|
161
|
|
|
$this->connection->setProfiler($profiler); |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|