1 | <?php |
||
2 | /** |
||
3 | * Select fields |
||
4 | * User: moyo |
||
5 | * Date: 25/12/2017 |
||
6 | * Time: 12:17 PM |
||
7 | */ |
||
8 | |||
9 | namespace Carno\Database\SQL\Builders; |
||
10 | |||
11 | use Carno\Database\SQL\Builder; |
||
12 | |||
13 | trait Select |
||
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $bSelect = '*'; |
||
19 | |||
20 | /** |
||
21 | * @return string |
||
22 | */ |
||
23 | protected function gSelect() : string |
||
24 | { |
||
25 | return $this->bSelect; |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @param array ...$fields |
||
30 | * @return Builder |
||
31 | */ |
||
32 | public function select(...$fields) : Builder |
||
33 | { |
||
34 | if (is_string($fields[0] ?? false)) { |
||
35 | if (count($fields) === 1) { |
||
36 | // select(expr) |
||
37 | $this->bSelect = $fields[0]; |
||
38 | } else { |
||
39 | // select(f1, f2) |
||
40 | $selects = []; |
||
41 | array_walk($fields, function (string $val) use (&$selects) { |
||
42 | $selects[] = is_numeric(strpos($val, ' ')) ? $val : sprintf('`%s`', $val); |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
43 | }); |
||
44 | $this->bSelect = implode(',', $selects); |
||
45 | } |
||
46 | } |
||
47 | |||
48 | return $this; |
||
0 ignored issues
–
show
|
|||
49 | } |
||
50 | } |
||
51 |