|
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 |
|
public function __set($name, $value) { |
|
59
|
1 |
|
$properties = $this->model->getProperties(); |
|
60
|
1 |
|
if (isset($properties[$name][P_DB_FIELD_TYPE])) { |
|
61
|
1 |
|
$value = \classSupernova::$gc->types->castAs($properties[$name][P_DB_FIELD_TYPE], $value); |
|
|
|
|
|
|
62
|
1 |
|
} |
|
63
|
|
|
|
|
64
|
1 |
|
parent::__set($name, $value); |
|
65
|
|
|
// If it is first assign - saving this value as original |
|
66
|
1 |
|
if (!array_key_exists($name, $this->original)) { |
|
67
|
1 |
|
$this->original[$name] = $value; |
|
68
|
1 |
|
} // If it is not first assign |
|
69
|
1 |
|
elseif ($value != $this->original[$name] && (is_int($value) || is_float($value))) { |
|
70
|
|
|
// // New value not equal original value. We should update delta |
|
71
|
1 |
|
$this->delta[$name] = $value - $this->original[$name]; |
|
72
|
1 |
|
} |
|
73
|
1 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function clear() { |
|
76
|
|
|
parent::clear(); |
|
77
|
|
|
$this->original = array(); |
|
78
|
|
|
$this->delta = array(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
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: