[core] cleanup
This commit is contained in:
parent
2a494504f3
commit
2f05ef4a0b
1 changed files with 9 additions and 6 deletions
|
@ -19,9 +19,6 @@ function pop_val(array &$row, string $name): mixed
|
||||||
{
|
{
|
||||||
$value = $row[$name];
|
$value = $row[$name];
|
||||||
unset($row[$name]);
|
unset($row[$name]);
|
||||||
if(is_null($value)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
function pop_int(array &$row, string $name): ?int
|
function pop_int(array &$row, string $name): ?int
|
||||||
|
@ -95,6 +92,15 @@ class Image implements \ArrayAccess
|
||||||
public function __construct(?array $row = null)
|
public function __construct(?array $row = null)
|
||||||
{
|
{
|
||||||
if (!is_null($row)) {
|
if (!is_null($row)) {
|
||||||
|
// some databases return both key=>value and numeric indices,
|
||||||
|
// we only want the key=>value ones
|
||||||
|
foreach ($row as $name => $value) {
|
||||||
|
if (is_numeric($name)) {
|
||||||
|
unset($row[$name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pull out known fields
|
||||||
$this->id = pop_int($row, 'id');
|
$this->id = pop_int($row, 'id');
|
||||||
$this->hash = pop_val($row, 'hash');
|
$this->hash = pop_val($row, 'hash');
|
||||||
$this->filename = pop_val($row, 'filename');
|
$this->filename = pop_val($row, 'filename');
|
||||||
|
@ -117,9 +123,6 @@ class Image implements \ArrayAccess
|
||||||
|
|
||||||
// Any remaining fields are dynamic properties
|
// Any remaining fields are dynamic properties
|
||||||
foreach ($row as $name => $value) {
|
foreach ($row as $name => $value) {
|
||||||
if (is_numeric($name)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(property_exists($this, $name)) {
|
if(property_exists($this, $name)) {
|
||||||
throw new \Exception("Property $name already exists on Image");
|
throw new \Exception("Property $name already exists on Image");
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue