Skip to content

Commit 09bdfd4

Browse files
committed
feat: add autoCasting flag to enable/disable autoCasting in DataObject
1 parent a631c74 commit 09bdfd4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/support/src/DataObject.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ abstract class DataObject implements ArrayAccess, JsonSerializable
2828
*/
2929
protected array $arrayCache = [];
3030

31+
/**
32+
* Flag to indicate if auto-casting is enabled.
33+
*/
34+
protected static bool $autoCasting = true;
35+
3136
/**
3237
* Create an instance of the class using the provided data array.
3338
*/
@@ -47,7 +52,9 @@ public static function make(array $data): static
4752
// and convert the value to the correct type automatically
4853
if (array_key_exists($dataKey, $data)) {
4954
$dataValue = $data[$dataKey];
50-
$dataValue = static::convertValueToType($dataValue, $parameter);
55+
if (static::$autoCasting) {
56+
$dataValue = static::convertValueToType($dataValue, $parameter);
57+
}
5158
// use the default value if available
5259
} elseif ($parameter->isDefaultValueAvailable()) {
5360
$dataValue = $parameter->getDefaultValue();

0 commit comments

Comments
 (0)