Total Complexity | 13 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
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 | case 'datetime': |
||
21 | $value = (date_format( date_create_from_format(DATAMANAGER_CONFIG['datetimeformat'],$value) , 'Y-m-d H:i:s')); |
||
22 | break; |
||
23 | } |
||
24 | } |
||
25 | |||
26 | $this->isSettable($prop); |
||
27 | |||
28 | $this->data[$prop]['changed'] = ($prop === $this->primary) ? false : true; |
||
29 | $this->data[$prop]['value'] = $value; |
||
30 | |||
31 | $this->$prop = $value; |
||
32 | |||
33 | return $this; |
||
34 | } |
||
35 | |||
36 | public function get(string $field){ |
||
37 | return $this->data[$field]['value']; |
||
38 | } |
||
39 | |||
40 | public function __get(string $field) |
||
56 | } |
||
57 | } |