Skip to content

Commit fb3ff4c

Browse files
committed
Changed the internal behavior of aliasReplacer
1 parent 8f46435 commit fb3ff4c

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

src/Builder/Delete.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __toString() {
4646
throw new Exception('Specify a table-name');
4747
}
4848

49-
$sqlTable = (new AliasReplacer($this->db()->getAliasRegistry()))->replace($this->table);
49+
$sqlTable = $this->aliasReplacer()->replace($this->table);
5050
$queryArr = array();
5151
$queryArr[] = "DELETE "."FROM\n\t{$sqlTable}\n";
5252

src/Builder/Insert.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,10 @@ public function __toString() {
181181
throw new Exception('Specify a table-name');
182182
}
183183

184+
$tableName = $this->aliasReplacer()->replace($this->table);
185+
184186
$fields = $this->fields;
185-
$tableFields = $this->db()->getTableFields($this->table);
187+
$tableFields = $this->db()->getTableFields($tableName);
186188

187189
$insertData = $this->buildFieldList($fields, $tableFields);
188190
$updateData = $this->buildUpdate();
@@ -191,8 +193,6 @@ public function __toString() {
191193
throw new Exception('No field-data found');
192194
}
193195

194-
$tableName = (new AliasReplacer($this->db()->getAliasRegistry()))->replace($this->table);
195-
196196
$queryArr = array();
197197
$ignoreStr = $this->ignore ? ' IGNORE' : '';
198198
$queryArr[] = "INSERT{$ignoreStr} INTO\n\t{$tableName}\n";

src/Builder/Select.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ private function buildTableName($alias, $name) {
429429
$name = join("\n", $lines);
430430
$name = '(' . trim(rtrim(trim($name), ';')) . ')';
431431
}
432-
$name = (new AliasReplacer($this->db()->getAliasRegistry()))->replace($name);
432+
$name = $this->aliasReplacer()->replace($name);
433433
return sprintf("%s %s", $name, $alias);
434434
}
435435

src/Builder/Statement.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@
22
namespace Kir\MySQL\Builder;
33

44
use Kir\MySQL\Database;
5+
use Kir\MySQL\Tools\AliasReplacer;
56

67
abstract class Statement {
78
/**
8-
* @var
9+
* @var Database
910
*/
1011
private $db;
1112

13+
/**
14+
* @var AliasReplacer
15+
*/
16+
private $aliasReplacer;
17+
1218
/**
1319
* @param Database $db
1420
*/
1521
public function __construct(Database $db) {
1622
$this->db = $db;
23+
$this->aliasReplacer = new AliasReplacer($db->getAliasRegistry());
1724
}
1825

1926
/**
@@ -39,6 +46,13 @@ public function cloneStatement() {
3946
return clone $this;
4047
}
4148

49+
/**
50+
* @return AliasReplacer
51+
*/
52+
public function aliasReplacer() {
53+
return $this->aliasReplacer;
54+
}
55+
4256
/**
4357
* @return Database
4458
*/

src/Builder/Update.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ public function __toString() {
9494
throw new Exception('Specify a table-name');
9595
}
9696

97-
$tableFields = $this->db()->getTableFields($this->table);
97+
$tableName = $this->aliasReplacer()->replace($this->table);
98+
99+
$tableFields = $this->db()->getTableFields($tableName);
98100
$sqlFields = $this->buildFieldList($this->fields, $tableFields);
99101

100102
if (empty($sqlFields)) {
101103
throw new Exception('No field-data found');
102104
}
103105

104-
$tableName = (new AliasReplacer($this->db()->getAliasRegistry()))->replace($this->table);
105-
106106
$queryArr = array();
107107
$queryArr[] = "UPDATE\n\t{$tableName}\nSET\n{$sqlFields}\n";
108108

0 commit comments

Comments
 (0)