/
Delete.php
64 lines (52 loc) · 1.28 KB
/
Delete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace Muffin\Queries;
use Muffin\Query;
use Muffin\Condition;
use Muffin\Traits\EscaperAware;
use Muffin\Snippet;
use Muffin\Queries\Snippets\Builders;
class Delete implements Query
{
use
EscaperAware,
Builders\Join,
Builders\Where,
Builders\OrderBy,
Builders\Limit;
private
$from;
public function __construct($table = null, $alias = null)
{
if(!empty($table))
{
$this->from($table, $alias);
}
$this->where = new Snippets\Where();
$this->orderBy = new Snippets\OrderBy();
}
public function toString()
{
$queryParts = array(
'DELETE',
$this->buildFrom(),
$this->buildJoin(),
$this->buildWhere($this->escaper),
$this->buildOrderBy(),
$this->buildLimit(),
);
return implode(' ', array_filter($queryParts));
}
public function from($table, $alias = null)
{
$this->from = new Snippets\From($table, $alias);
return $this;
}
private function buildFrom()
{
if(!$this->from instanceof Snippet)
{
throw new \LogicException('No column for FROM clause');
}
return $this->from->toString();
}
}