|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Tests\Support\Stub; |
|
6
|
|
|
|
|
7
|
|
|
use PDO; |
|
8
|
|
|
use Yiisoft\Db\Command\CommandInterface; |
|
9
|
|
|
use Yiisoft\Db\Driver\PDO\ConnectionPDO; |
|
10
|
|
|
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; |
|
11
|
|
|
use Yiisoft\Db\Schema\Quoter; |
|
12
|
|
|
use Yiisoft\Db\Schema\QuoterInterface; |
|
13
|
|
|
use Yiisoft\Db\Schema\SchemaInterface; |
|
14
|
|
|
use Yiisoft\Db\Transaction\TransactionInterface; |
|
15
|
|
|
|
|
16
|
|
|
final class Connection extends ConnectionPDO |
|
17
|
|
|
{ |
|
18
|
|
|
protected QueryBuilderInterface|null $queryBuilder = null; |
|
19
|
|
|
protected SchemaInterface|null $schema = null; |
|
20
|
|
|
|
|
21
|
|
|
public function createCommand(string $sql = null, array $params = []): CommandInterface |
|
22
|
|
|
{ |
|
23
|
|
|
$command = new Command($this, $this->queryCache); |
|
24
|
|
|
|
|
25
|
|
|
if ($sql !== null) { |
|
26
|
|
|
$command->setSql($sql); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
if ($this->logger !== null) { |
|
30
|
|
|
$command->setLogger($this->logger); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if ($this->profiler !== null) { |
|
34
|
|
|
$command->setProfiler($this->profiler); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
return $command->bindValues($params); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function createTransaction(): TransactionInterface |
|
41
|
|
|
{ |
|
42
|
|
|
return new Transaction($this); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function getQueryBuilder(): QueryBuilderInterface |
|
46
|
|
|
{ |
|
47
|
|
|
if ($this->queryBuilder === null) { |
|
48
|
|
|
$this->queryBuilder = new QueryBuilder( |
|
49
|
|
|
$this->getQuoter(), |
|
50
|
|
|
$this->getSchema(), |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return $this->queryBuilder; |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getQuoter(): QuoterInterface |
|
58
|
|
|
{ |
|
59
|
|
|
if ($this->quoter === null) { |
|
60
|
|
|
$this->quoter = new Quoter(['[', ']'], ['[', ']'], $this->getTablePrefix()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $this->quoter; |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getMigrationBuilder(): MigrationBuilder |
|
67
|
|
|
{ |
|
68
|
|
|
return new MigrationBuilder($this->getSchema()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getSchema(): SchemaInterface |
|
72
|
|
|
{ |
|
73
|
|
|
if ($this->schema === null) { |
|
74
|
|
|
$this->schema = new Schema($this, $this->schemaCache); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $this->schema; |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
protected function initConnection(): void |
|
81
|
|
|
{ |
|
82
|
|
|
if ($this->getEmulatePrepare() !== null) { |
|
83
|
|
|
$this->driver->attributes([PDO::ATTR_EMULATE_PREPARES => $this->getEmulatePrepare()]); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$this->pdo = $this->driver->createConnection(); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|