DbObjectTypeRegistry: new helper methods
This commit is contained in:
parent
1845b43314
commit
ce13200832
|
@ -3,9 +3,14 @@
|
||||||
namespace Icinga\Module\Director\Data\Db;
|
namespace Icinga\Module\Director\Data\Db;
|
||||||
|
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
|
use Icinga\Module\Director\Objects\IcingaObject;
|
||||||
|
|
||||||
class DbObjectTypeRegistry
|
class DbObjectTypeRegistry
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param $type
|
||||||
|
* @return string|DbObject Fake typehint for IDE
|
||||||
|
*/
|
||||||
public static function classByType($type)
|
public static function classByType($type)
|
||||||
{
|
{
|
||||||
// allow for icinga_host and host
|
// allow for icinga_host and host
|
||||||
|
@ -44,6 +49,23 @@ class DbObjectTypeRegistry
|
||||||
return 'Icinga\\Module\\Director\\Objects\\' . $prefix . ucfirst($type);
|
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)
|
public static function newObject($type, $properties = [], Db $db = null)
|
||||||
{
|
{
|
||||||
/** @var DbObject $class fake hint for the IDE, it's a string */
|
/** @var DbObject $class fake hint for the IDE, it's a string */
|
||||||
|
|
Loading…
Reference in New Issue