Skip to content

Commit 36ea031

Browse files
committed
Allow UUIDs for Blameable fields
AbstractTrackingListener: Check for a setter method when updating a field and use that one instead of setting the property value directly. This allows converting the given value to whatever type is required.
1 parent 9c46ada commit 36ea031

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/AbstractTrackingListener.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,14 @@ protected function updateField($object, $eventAdapter, $meta, $field)
223223
}
224224
}
225225

226-
$property->setValue($object, $newValue);
226+
$setterName = 'set' . ucfirst($field);
227+
$reflectionClass = $meta->getReflectionClass();
228+
229+
if ($reflectionClass->hasMethod($setterName)) {
230+
$reflectionClass->getMethod($setterName)->invoke($object, $newValue);
231+
} else {
232+
$property->setValue($object, $newValue);
233+
}
227234

228235
if ($object instanceof NotifyPropertyChanged) {
229236
$uow = $eventAdapter->getObjectManager()->getUnitOfWork();

src/Blameable/Mapping/Driver/Annotation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Annotation extends AbstractAnnotationDriver
3939
'one',
4040
'string',
4141
'int',
42+
'uuid',
4243
];
4344

4445
public function readExtendedMetadata($meta, array &$config)

0 commit comments

Comments
 (0)