1 | <?php |
||
29 | class PreUpdateEventArgs extends LifecycleEventArgs |
||
30 | { |
||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | private $documentChangeSet; |
||
35 | |||
36 | /** |
||
37 | * Constructor. |
||
38 | * |
||
39 | * @param object $document |
||
40 | * @param DocumentManager $dm |
||
41 | * @param array $changeSet |
||
42 | */ |
||
43 | 231 | public function __construct($document, DocumentManager $dm, array $changeSet) |
|
44 | { |
||
45 | 231 | parent::__construct($document, $dm); |
|
46 | 231 | $this->documentChangeSet = $changeSet; |
|
47 | 231 | } |
|
48 | |||
49 | /** |
||
50 | * Retrieves the document changeset. |
||
51 | * |
||
52 | * @return array |
||
53 | */ |
||
54 | public function getDocumentChangeSet() |
||
58 | |||
59 | /** |
||
60 | * Checks if field has a changeset. |
||
61 | * |
||
62 | * @param string $field |
||
63 | * |
||
64 | * @return boolean |
||
65 | */ |
||
66 | 1 | public function hasChangedField($field) |
|
70 | |||
71 | /** |
||
72 | * Gets the old value of the changeset of the changed field. |
||
73 | * |
||
74 | * @param string $field |
||
75 | * @return mixed |
||
76 | */ |
||
77 | public function getOldValue($field) |
||
83 | |||
84 | /** |
||
85 | * Gets the new value of the changeset of the changed field. |
||
86 | * |
||
87 | * @param string $field |
||
88 | * @return mixed |
||
89 | */ |
||
90 | public function getNewValue($field) |
||
96 | |||
97 | /** |
||
98 | * Sets the new value of this field. |
||
99 | * |
||
100 | * @param string $field |
||
101 | * @param mixed $value |
||
102 | */ |
||
103 | 1 | public function setNewValue($field, $value) |
|
104 | { |
||
105 | 1 | $this->assertValidField($field); |
|
106 | |||
107 | 1 | $this->documentChangeSet[$field][1] = $value; |
|
108 | 1 | $this->getDocumentManager()->getUnitOfWork()->setDocumentChangeSet($this->getDocument(), $this->documentChangeSet); |
|
109 | 1 | } |
|
110 | |||
111 | /** |
||
112 | * Asserts the field exists in changeset. |
||
113 | * |
||
114 | * @param string $field |
||
115 | * @throws \InvalidArgumentException if the field has no changeset |
||
116 | */ |
||
117 | 1 | private function assertValidField($field) |
|
127 | } |
||
128 |