web/lib/OrmBase.php
2021-12-09 13:13:16 -06:00

30 lines
694 B
PHP

<?
use function Safe\substr;
abstract class OrmBase{
public static function FillObject($object, $row){
foreach($row as $property => $value){
if(substr($property, strlen($property) - 9) == 'Timestamp'){
if($value !== null){
$object->$property = new DateTime($value, new DateTimeZone('UTC'));
}
else{
$object->$property = null;
}
}
elseif(substr($property, strlen($property) - 5) == 'Cache'){
$property = substr($property, 0, strlen($property) - 5);
$object->$property = $value;
}
else{
$object->$property = $value;
}
}
return $object;
}
public static function FromRow($row){
return self::FillObject(new static(), $row);
}
}