|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace StefanoTree\NestedSet\Adapter; |
|
6
|
|
|
|
|
7
|
|
|
use Laminas\Db\Adapter\Adapter as DbAdapter; |
|
8
|
|
|
use StefanoTree\NestedSet\Options; |
|
9
|
|
|
|
|
10
|
|
|
class LaminasDb implements AdapterInterface |
|
11
|
|
|
{ |
|
12
|
|
|
private $connection; |
|
13
|
|
|
private $options; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @param Options $options |
|
17
|
|
|
* @param DbAdapter $connection |
|
18
|
|
|
*/ |
|
19
|
|
|
public function __construct(Options $options, DbAdapter $connection) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->connection = $connection; |
|
22
|
|
|
$this->options = $options; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @return DbAdapter |
|
27
|
|
|
*/ |
|
28
|
|
|
private function getConnection(): DbAdapter |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->connection; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return Options |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getOptions(): Options |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->options; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function beginTransaction(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$this->getConnection() |
|
44
|
|
|
->getDriver() |
|
45
|
|
|
->getConnection() |
|
46
|
|
|
->beginTransaction(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function commitTransaction(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$this->getConnection() |
|
52
|
|
|
->getDriver() |
|
53
|
|
|
->getConnection() |
|
54
|
|
|
->commit(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function rollbackTransaction(): void |
|
58
|
|
|
{ |
|
59
|
|
|
$this->getConnection() |
|
60
|
|
|
->getDriver() |
|
61
|
|
|
->getConnection() |
|
62
|
|
|
->rollback(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function isInTransaction(): bool |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->getConnection() |
|
68
|
|
|
->getDriver() |
|
69
|
|
|
->getConnection() |
|
70
|
|
|
->inTransaction(); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function canHandleNestedTransaction(): bool |
|
74
|
|
|
{ |
|
75
|
|
|
return true; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function quoteIdentifier(string $columnName): string |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->getConnection() |
|
81
|
|
|
->getPlatform() |
|
82
|
|
|
->quoteIdentifierChain(explode('.', $columnName)); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function executeInsertSQL(string $sql, array $params = array()) |
|
86
|
|
|
{ |
|
87
|
|
|
$options = $this->getOptions(); |
|
88
|
|
|
$this->executeSQL($sql, $params); |
|
89
|
|
|
|
|
90
|
|
|
if (array_key_exists($options->getIdColumnName(), $params)) { |
|
91
|
|
|
return $params[$options->getIdColumnName()]; |
|
92
|
|
|
} else { |
|
93
|
|
|
$lastGeneratedValue = $this->getConnection() |
|
94
|
|
|
->getDriver() |
|
95
|
|
|
->getLastGeneratedValue($options->getSequenceName()); |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
return $lastGeneratedValue; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function executeSQL(string $sql, array $params = array()): void |
|
102
|
|
|
{ |
|
103
|
|
|
$this->getConnection() |
|
104
|
|
|
->query($sql, $params); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function executeSelectSQL(string $sql, array $params = array()): array |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->getConnection() |
|
110
|
|
|
->query($sql, $params) |
|
111
|
|
|
->toArray(); |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.