From ce13200832497b120cc68ae6547e4745a78a08e4 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 5 Oct 2021 22:37:57 +0200 Subject: [PATCH] DbObjectTypeRegistry: new helper methods --- .../Director/Data/Db/DbObjectTypeRegistry.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/library/Director/Data/Db/DbObjectTypeRegistry.php b/library/Director/Data/Db/DbObjectTypeRegistry.php index fc16794a..0c226d65 100644 --- a/library/Director/Data/Db/DbObjectTypeRegistry.php +++ b/library/Director/Data/Db/DbObjectTypeRegistry.php @@ -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 */