Allow for an object's own FromRow method in DbConnection

This commit is contained in:
Alex Cabal 2024-05-01 09:08:10 -05:00
parent 50efeb05d1
commit 97cafbf128

View file

@ -171,8 +171,15 @@ class DbConnection{
$rows = $handle->fetchAll(\PDO::FETCH_NUM); $rows = $handle->fetchAll(\PDO::FETCH_NUM);
$useObjectFillMethod = method_exists($class, 'FromRow');
foreach($rows as $row){ foreach($rows as $row){
$object = new $class(); if($useObjectFillMethod){
$object = new stdClass();
}
else{
$object = new $class();
}
for($i = 0; $i < $handle->columnCount(); $i++){ for($i = 0; $i < $handle->columnCount(); $i++){
if($metadata[$i] === false){ if($metadata[$i] === false){
@ -246,7 +253,12 @@ class DbConnection{
} }
} }
$result[] = $object; if($useObjectFillMethod){
$result[] = $class::FromRow($object);
}
else{
$result[] = $object;
}
} }
} }
catch(\PDOException $ex){ catch(\PDOException $ex){