-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathUpdateQuery.php
66 lines (58 loc) · 1.5 KB
/
UpdateQuery.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
65
66
<?php
namespace Aternos\Model\Query;
/**
* Class UpdateQuery
*
* @package Aternos\Model\Query
*/
class UpdateQuery extends Query
{
/**
* @var UpdateField[]
*/
protected ?array $fields = null;
/**
* UpdateQuery constructor.
*
* @param array|null $fields
* @param array|WhereCondition|WhereGroup|null $where
* @param array|null $order
* @param array|int|Limit|null $limit
*/
public function __construct(null|array $fields = null,
null|WhereCondition|array|WhereGroup $where = null,
null|array $order = null,
null|Limit|array|int $limit = null)
{
if ($fields) {
$this->fields($fields);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->orderBy($order);
}
if ($limit) {
$this->limit($limit);
}
}
/**
* Set fields
*
* @param array $fields
* @return $this
*/
public function fields(array $fields): static
{
$this->fields = [];
foreach ($fields as $key => $field) {
if ($field instanceof UpdateField) {
$this->fields[] = $field;
} else if (is_string($key)) {
$this->fields[] = new UpdateField($key, $field);
}
}
return $this;
}
}