blob: 5f45ed45f011b2d575652aee551a2ffd4c6da14d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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;
}
}
|