summaryrefslogtreecommitdiff
path: root/src/Model.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model.php')
-rw-r--r--src/Model.php19
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;
+ }
+}