|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Isolate\UnitOfWork\Entity\Value\Change; |
|
4
|
|
|
|
|
5
|
|
|
use Isolate\UnitOfWork\Entity\Definition\Property; |
|
6
|
|
|
use Isolate\UnitOfWork\Entity\Value\Change; |
|
7
|
|
|
use Isolate\UnitOfWork\Entity\Value\Change\EditedEntity; |
|
8
|
|
|
use Isolate\UnitOfWork\Entity\Value\Change\NewEntity; |
|
9
|
|
|
use Isolate\UnitOfWork\Entity\Value\Change\RemovedEntity; |
|
10
|
|
|
|
|
11
|
|
|
final class AssociatedCollection implements Change |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var mixed |
|
15
|
|
|
*/ |
|
16
|
|
|
private $originValue; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var mixed |
|
20
|
|
|
*/ |
|
21
|
|
|
private $newValue; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var Property |
|
25
|
|
|
*/ |
|
26
|
|
|
private $property; |
|
27
|
|
|
/** |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
private $changes; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param Property $property |
|
34
|
|
|
* @param $originValue |
|
35
|
|
|
* @param $newValue |
|
36
|
|
|
* @param array $changes |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(Property $property, $originValue, $newValue, array $changes) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->property = $property; |
|
41
|
|
|
$this->originValue = $originValue; |
|
42
|
|
|
$this->newValue = $newValue; |
|
43
|
|
|
$this->changes = $changes; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return mixed |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getOriginValue() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->originValue; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return mixed |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getNewValue() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->newValue; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return Property |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getProperty() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->property; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return array|NewEntity[] |
|
72
|
|
|
* |
|
73
|
|
|
* @api |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getChangeForNewEntities() |
|
76
|
|
|
{ |
|
77
|
|
|
$new = []; |
|
78
|
|
|
foreach ($this->changes as $change) { |
|
79
|
|
|
if ($change instanceof NewEntity) { |
|
80
|
|
|
$new[] = $change; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $new; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return array|RemovedEntity[] |
|
89
|
|
|
* |
|
90
|
|
|
* @api |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getChangesForRemovedEntities() |
|
93
|
|
|
{ |
|
94
|
|
|
$removed = []; |
|
95
|
|
|
foreach ($this->changes as $change) { |
|
96
|
|
|
if ($change instanceof RemovedEntity) { |
|
97
|
|
|
$removed[] = $change; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $removed; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return array|EditedEntity[] |
|
106
|
|
|
* |
|
107
|
|
|
* @api |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getChangesForEditedEntities() |
|
110
|
|
|
{ |
|
111
|
|
|
$edited = []; |
|
112
|
|
|
foreach ($this->changes as $change) { |
|
113
|
|
|
if ($change instanceof EditedEntity) { |
|
114
|
|
|
$edited[] = $change; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
return $edited; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param $propertyName |
|
123
|
|
|
* @return bool |
|
124
|
|
|
*/ |
|
125
|
|
|
public function isFor($propertyName) |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->property->getName() === $propertyName; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|