implement to_json method so that defaults get included

This commit is contained in:
Isaac Connor 2019-01-15 11:36:56 -05:00
parent 34224a957b
commit 3182d8bab7
1 changed files with 14 additions and 0 deletions

View File

@ -214,5 +214,19 @@ class Server {
return $results[0];
}
public function to_json() {
$json = array();
foreach ($this->defaults as $key => $value) {
if ( is_callable(array($this, $key)) ) {
$json[$key] = $this->$key();
} else if ( array_key_exists($key, $this) ) {
$json[$key] = $this->{$key};
} else {
$json[$key] = $this->defaults{$key};
}
}
return json_encode($json);
}
} # end class Server
?>