Total Complexity | 13 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 6 | ||
Bugs | 0 | Features | 2 |
1 | <?php |
||
5 | trait MagicsTrait{ |
||
6 | |||
7 | public function __set(string $prop,$value) |
||
8 | { |
||
9 | if(is_array($value)){ |
||
10 | $attr = array_keys($value)[0]; |
||
11 | $this->data[$prop][$attr] = $value[$attr]; |
||
12 | return $this; |
||
13 | } |
||
14 | |||
15 | if($this->full){ |
||
16 | switch($this->data[$prop]['type']){ |
||
17 | case 'date': |
||
18 | $value = (date_format( date_create_from_format(DATAMANAGER_CONFIG['dateformat'],$value) , 'Y-m-d')); |
||
19 | break; |
||
20 | } |
||
21 | } |
||
22 | |||
23 | $this->isSettable($prop); |
||
24 | |||
25 | $this->data[$prop]['changed'] = ($prop === $this->primary) ? false : true; |
||
26 | $this->data[$prop]['value'] = $value; |
||
27 | |||
28 | return $this; |
||
29 | } |
||
30 | |||
31 | public function getVars(): array |
||
32 | { |
||
33 | $vars = []; |
||
34 | foreach($this->data as $var => $value){ |
||
35 | $vars[$var] = null; |
||
36 | } |
||
37 | return $vars; |
||
38 | } |
||
39 | |||
40 | public function __get(string $field) |
||
41 | { |
||
42 | $this->isSettable($field); |
||
43 | |||
44 | if($this->full){ |
||
45 | switch($this->data[$field]['type']){ |
||
46 | case 'date': |
||
47 | return (!empty($this->data[$field]['value'])) ? (@date_format( @date_create_from_format('Y-m-d' , $this->data[$field]['value'] ) , DATAMANAGER_CONFIG['dateformat'])) : null ; |
||
48 | break; |
||
49 | case 'datetime': |
||
50 | return (!empty($this->data[$field]['value'])) ? (@date_format( @date_create_from_format('Y-m-d H:i:s' , $this->data[$field]['value'] ) , DATAMANAGER_CONFIG['datetimeformat'])) : null ; |
||
51 | break; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | return $this->data[$field]['value']; |
||
56 | } |
||
57 | } |