DbObjectTypeRegistry: new helper methods

This commit is contained in:
Thomas Gelf 2021-10-05 22:37:57 +02:00
parent 1845b43314
commit ce13200832
1 changed files with 22 additions and 0 deletions

View File

@ -3,9 +3,14 @@
namespace Icinga\Module\Director\Data\Db;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Objects\IcingaObject;
class DbObjectTypeRegistry
{
/**
* @param $type
* @return string|DbObject Fake typehint for IDE
*/
public static function classByType($type)
{
// allow for icinga_host and host
@ -44,6 +49,23 @@ class DbObjectTypeRegistry
return 'Icinga\\Module\\Director\\Objects\\' . $prefix . ucfirst($type);
}
public static function tableNameByType($type)
{
$class = static::classByType($type);
$dummy = $class::create([]);
return $dummy->getTableName();
}
public static function shortTypeForObject(DbObject $object)
{
if ($object instanceof IcingaObject) {
return $object->getShortTableName();
}
return $object->getTableName();
}
public static function newObject($type, $properties = [], Db $db = null)
{
/** @var DbObject $class fake hint for the IDE, it's a string */