-
Notifications
You must be signed in to change notification settings - Fork 0
/
EntityTrait.php
executable file
·50 lines (41 loc) · 1.05 KB
/
EntityTrait.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
<?php
namespace AE\Stdlib;
trait EntityTrait
{
public function __construct()
{
}
public function toValues()
{
$filterArray = array_filter(get_object_vars($this));
return array_values($filterArray);
}
public function jsonSerialize()
{
$objectArray = [];
foreach($this as $key => $value) {
$objectArray[$key] = $value;
}
return $objectArray;
}
public function getFilterNames()
{
$filterArray = get_object_vars($this);
$filterNames = array_keys(array_filter($filterArray));
$sqlFragments = [];
foreach($filterNames as $filter) {
$sqlFragments[] = '' . $filter . '=? ';
}
$sql = implode(" AND ", $sqlFragments);
return $sql;
}
// To Array, remove null values from filter
public function toArray()
{
$objectAsArray = [];
foreach(get_object_vars($this) as $key => $value) {
$objectAsArray[$key] = $value;
}
return $objectAsArray;
}
}