mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-27 07:44:05 +02:00
DbObject: allow arrays in fromDbRow, handle errors
This commit is contained in:
parent
6a68a2c3d8
commit
2994403aa8
@ -3,6 +3,7 @@
|
|||||||
namespace Icinga\Module\Director\Data\Db;
|
namespace Icinga\Module\Director\Data\Db;
|
||||||
|
|
||||||
use Icinga\Exception\NotFoundError;
|
use Icinga\Exception\NotFoundError;
|
||||||
|
use Icinga\Module\Director\Data\InvalidDataException;
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
use Icinga\Module\Director\Exception\DuplicateKeyException;
|
use Icinga\Module\Director\Exception\DuplicateKeyException;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
@ -696,15 +697,22 @@ abstract class DbObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param object $row
|
* @param object|array $row
|
||||||
* @param Db $db
|
* @param Db $db
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public static function fromDbRow($row, Db $db)
|
public static function fromDbRow($row, Db $db)
|
||||||
{
|
{
|
||||||
return (new static())
|
$self = (new static())->setConnection($db);
|
||||||
->setConnection($db)
|
if (is_object($row)) {
|
||||||
->setDbProperties($row);
|
return $self->setDbProperties((array) $row);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($row)) {
|
||||||
|
return $self->setDbProperties($row);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new InvalidDataException('array or object', $row);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setDbProperties($properties)
|
protected function setDbProperties($properties)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user