diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-09-24 13:40:25 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-09-24 13:40:25 +0200 |
commit | fa00b957378a393f8edbfc98ef111d35d18ecb09 (patch) | |
tree | 654e7dc5414f7f2795dbe996d3e1570793a5b1b8 /src/Model.php |
initial commit
Diffstat (limited to 'src/Model.php')
-rw-r--r-- | src/Model.php | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/Model.php b/src/Model.php new file mode 100644 index 0000000..5f45ed4 --- /dev/null +++ b/src/Model.php @@ -0,0 +1,19 @@ +<?php + +namespace App; + +class Model +{ + public static function castToType(object $original, string $cast): object + { + $object = new $cast(); + + foreach (get_class_vars(get_class($original)) as $property => $_) { + if (! empty($original->$property) && empty($object->$property)) { + $object->$property = $original->$property; + } + } + + return $object; + } +} |