1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Entity; |
4
|
|
|
|
5
|
|
|
use Common\ContainerAccessors; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Entity\EntityContainer |
9
|
|
|
* |
10
|
|
|
* @property array $row - Entity row read from DB |
11
|
|
|
*/ |
12
|
|
|
class EntityContainer extends ContainerAccessors { |
13
|
|
|
/** |
14
|
|
|
* @var EntityModel $model |
15
|
|
|
*/ |
16
|
|
|
protected $model; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var \Common\Accessors $accessors |
20
|
|
|
*/ |
21
|
|
|
protected $accessors; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var array $original |
25
|
|
|
*/ |
26
|
|
|
protected $original = array(); |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var array $delta |
30
|
|
|
*/ |
31
|
|
|
protected $delta = array(); |
32
|
|
|
|
33
|
|
|
/** @noinspection PhpMissingParentConstructorInspection */ |
34
|
|
|
/** |
35
|
|
|
* Entity\EntityContainer constructor. |
36
|
|
|
* |
37
|
|
|
* @param EntityModel $model |
38
|
|
|
*/ |
39
|
1 |
|
public function __construct($model) { |
40
|
1 |
|
$this->setModel($model); |
41
|
1 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param EntityModel $model |
45
|
|
|
*/ |
46
|
1 |
|
public function setModel(EntityModel $model) { |
47
|
1 |
|
$this->model = $model; |
48
|
1 |
|
$this->accessors = $model->getAccessors(); |
49
|
1 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return EntityModel |
53
|
|
|
*/ |
54
|
1 |
|
public function getModel() { |
55
|
1 |
|
return $this->model; |
56
|
|
|
} |
57
|
|
|
|
58
|
1 |
|
protected function processNumeric($name, $value) { |
59
|
1 |
|
if(!is_int($value) && !is_float($value)) { |
60
|
1 |
|
return; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// If no original value and new value is set - then we take new value as old value |
64
|
1 |
|
if(empty($this->original[$name]) && !empty($value)) { |
65
|
1 |
|
$this->original[$name] = $value; |
66
|
1 |
|
} elseif(!empty($this->original[$name]) && $value != $this->original[$name]) { |
67
|
|
|
// New value not equal original value. We should update delta |
68
|
1 |
|
$this->delta[$name] = $value - $this->original[$name]; |
69
|
1 |
|
} |
70
|
1 |
|
} |
71
|
|
|
|
72
|
1 |
|
public function __set($name, $value) { |
73
|
1 |
|
$properties = $this->model->getProperties(); |
74
|
1 |
|
if(isset($properties[$name][P_DB_FIELD_TYPE])) { |
75
|
1 |
|
$value = \classSupernova::$gc->types->castAs($properties[$name][P_DB_FIELD_TYPE], $value); |
|
|
|
|
76
|
1 |
|
} |
77
|
|
|
|
78
|
1 |
|
parent::__set($name, $value); |
79
|
1 |
|
$this->processNumeric($name, $value); |
80
|
1 |
|
} |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: