|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace StefanoTree\NestedSet\Adapter; |
|
6
|
|
|
|
|
7
|
|
|
use StefanoTree\NestedSet\Options; |
|
8
|
|
|
use Zend_Db_Adapter_Abstract as ZendDbAdapter; |
|
9
|
|
|
|
|
10
|
|
|
class Zend1 implements AdapterInterface |
|
11
|
|
|
{ |
|
12
|
|
|
private $connection; |
|
13
|
|
|
private $options; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @param Options $options |
|
17
|
|
|
* @param ZendDbAdapter $connection |
|
18
|
|
|
*/ |
|
19
|
8 |
|
public function __construct(Options $options, ZendDbAdapter $connection) |
|
20
|
|
|
{ |
|
21
|
8 |
|
$this->connection = $connection; |
|
22
|
8 |
|
$this->options = $options; |
|
23
|
8 |
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @return ZendDbAdapter |
|
27
|
|
|
*/ |
|
28
|
6 |
|
private function getConnection(): ZendDbAdapter |
|
29
|
|
|
{ |
|
30
|
6 |
|
return $this->connection; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return Options |
|
35
|
|
|
*/ |
|
36
|
1 |
|
public function getOptions(): Options |
|
37
|
|
|
{ |
|
38
|
1 |
|
return $this->options; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
3 |
|
public function beginTransaction(): void |
|
42
|
|
|
{ |
|
43
|
3 |
|
$this->getConnection() |
|
44
|
3 |
|
->beginTransaction(); |
|
45
|
3 |
|
} |
|
46
|
|
|
|
|
47
|
1 |
|
public function commitTransaction(): void |
|
48
|
|
|
{ |
|
49
|
1 |
|
$this->getConnection() |
|
50
|
1 |
|
->commit(); |
|
51
|
1 |
|
} |
|
52
|
|
|
|
|
53
|
2 |
|
public function rollbackTransaction(): void |
|
54
|
|
|
{ |
|
55
|
2 |
|
$this->getConnection() |
|
56
|
2 |
|
->rollBack(); |
|
57
|
2 |
|
} |
|
58
|
|
|
|
|
59
|
3 |
|
public function isInTransaction(): bool |
|
60
|
|
|
{ |
|
61
|
3 |
|
return $this->getConnection() |
|
62
|
3 |
|
->getConnection() |
|
63
|
3 |
|
->inTransaction(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function canHandleNestedTransaction(): bool |
|
67
|
|
|
{ |
|
68
|
|
|
return false; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
public function quoteIdentifier(string $columnName): string |
|
72
|
|
|
{ |
|
73
|
1 |
|
return $this->getConnection() |
|
74
|
1 |
|
->quoteIdentifier($columnName); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
1 |
|
public function executeInsertSQL(string $sql, array $params = array()) |
|
78
|
|
|
{ |
|
79
|
1 |
|
$options = $this->getOptions(); |
|
80
|
1 |
|
$this->executeSQL($sql, $params); |
|
81
|
|
|
|
|
82
|
1 |
|
if (array_key_exists($options->getIdColumnName(), $params)) { |
|
83
|
|
|
return $params[$options->getIdColumnName()]; |
|
84
|
|
|
} else { |
|
85
|
1 |
|
if ('' != $options->getSequenceName()) { |
|
86
|
1 |
|
$lastGeneratedValue = $this->getConnection() |
|
87
|
1 |
|
->lastSequenceId($options->getSequenceName()); |
|
88
|
|
|
} else { |
|
89
|
|
|
$lastGeneratedValue = $this->getConnection() |
|
90
|
|
|
->lastInsertId(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
1 |
|
return $lastGeneratedValue; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
2 |
|
public function executeSQL(string $sql, array $params = array()): void |
|
98
|
|
|
{ |
|
99
|
2 |
|
$this->getConnection() |
|
100
|
2 |
|
->query($sql, $params); |
|
101
|
2 |
|
} |
|
102
|
|
|
|
|
103
|
2 |
|
public function executeSelectSQL(string $sql, array $params = array()): array |
|
104
|
|
|
{ |
|
105
|
2 |
|
return $this->getConnection() |
|
106
|
2 |
|
->query($sql, $params) |
|
107
|
2 |
|
->fetchAll(); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|