IcingaObject: first simple toJson support

This commit is contained in:
Thomas Gelf 2015-12-02 03:08:57 +01:00
parent a2d1594eaf
commit d5c20e6e53

View File

@ -811,6 +811,33 @@ return '';
return $class::loadAll($db, $query, $keyColumn);
}
public function toJson($resolved = false)
{
$props = array();
foreach ($this->getProperties() as $k => $v) {
if ($v !== null) {
$props[$k] = $v;
}
}
if ($this->supportsGroups()) {
// TODO: resolve
$props['groups'] = $this->groups()->listGroupNames();
}
if ($this->supportsCustomVars()) {
if ($resolved) {
$props['vars'] = $this->getVars();
} else {
$props['vars'] = $this->getResolvedVars();
}
}
if ($this->supportsImports()) {
$props['imports'] = $this->imports()->listImportNames();
}
return json_encode($props);
}
public function __toString()
{
try {