implement to_json method so that defaults get included
This commit is contained in:
parent
34224a957b
commit
3182d8bab7
|
@ -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
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue