mirror of
https://github.com/standardebooks/web.git
synced 2025-07-15 10:56:46 -04:00
Add database and ORM scaffolding
This commit is contained in:
parent
42ba2f8680
commit
9d923605d8
8 changed files with 278 additions and 0 deletions
30
lib/OrmBase.php
Normal file
30
lib/OrmBase.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue