|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Compolomus\LSQLQueryBuilder; |
|
4
|
|
|
|
|
5
|
|
|
use Compolomus\LSQLQueryBuilder\{ |
|
6
|
|
|
System\Traits\Helper, |
|
7
|
|
|
Parts\Insert, |
|
8
|
|
|
Parts\Select, |
|
9
|
|
|
Parts\Update, |
|
10
|
|
|
Parts\Delete |
|
11
|
|
|
}; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @method Insert insert(array $args = []) |
|
15
|
|
|
* @method Select select(array $fields = []) |
|
16
|
|
|
* @method Update update(array $args = []) |
|
17
|
|
|
* @method Delete delete(integer $id = 0, string $field = 'id') |
|
18
|
|
|
*/ |
|
19
|
|
|
class Builder |
|
20
|
|
|
{ |
|
21
|
|
|
use Helper; |
|
22
|
|
|
|
|
23
|
|
|
private $table; |
|
24
|
|
|
|
|
25
|
|
|
private $placeholders = []; |
|
26
|
|
|
|
|
27
|
|
|
private $data = []; |
|
28
|
|
|
|
|
29
|
6 |
|
public function __construct(?string $table = null) |
|
30
|
|
|
{ |
|
31
|
6 |
|
if ($table) { |
|
32
|
3 |
|
$this->setTable($table); |
|
33
|
|
|
} |
|
34
|
6 |
|
} |
|
35
|
|
|
|
|
36
|
3 |
|
public function setTable(string $table): Builder |
|
37
|
|
|
{ |
|
38
|
3 |
|
$this->table = $table; |
|
39
|
3 |
|
return $this; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
4 |
|
public function table(): string |
|
43
|
|
|
{ |
|
44
|
4 |
|
return $this->table ? $this->escapeField($this->table) : ''; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function placeholders(): array |
|
48
|
|
|
{ |
|
49
|
|
|
$return = $this->placeholders; |
|
50
|
|
|
$this->placeholders = []; |
|
51
|
|
|
return $return; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function addPlaceholders($placeholders): void |
|
55
|
|
|
{ |
|
56
|
|
|
$this->placeholders += $placeholders; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
public function __set(string $name, $value): void |
|
60
|
|
|
{ |
|
61
|
1 |
|
$this->data[$name] = $value; |
|
62
|
1 |
|
} |
|
63
|
|
|
|
|
64
|
1 |
|
public function __get(string $name) |
|
65
|
|
|
{ |
|
66
|
1 |
|
return $this->data[$name] ?? null; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function __isset(string $name): bool |
|
70
|
|
|
{ |
|
71
|
|
|
return isset($this->data[$name]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function __unset(string $name): void |
|
75
|
|
|
{ |
|
76
|
|
|
unset($this->data[$name]); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
public function __call(string $name, $args) |
|
80
|
|
|
{ |
|
81
|
1 |
|
$class = "Compolomus\\LSQLQueryBuilder\\Parts\\" . ucfirst($name); |
|
82
|
1 |
|
if (class_exists($class)) { |
|
83
|
1 |
|
$this->$name = new $class(...$args); |
|
84
|
1 |
|
$this->$name->setBase($this); |
|
85
|
1 |
|
return $this->$name; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|