blob: 27204862abb32ef36caa45d995df22ec25eccb0a (
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 (isset($original->$property) && ! isset($object->$property)) {
$object->$property = $original->$property;
}
}
return $object;
}
}
|