public function addItem($key, $value)
{
// get our table name from the constructor
$tableName = $this->args[0];
$log = usingLog()->startAction("add entry '{$key}' to {$tableName} table");
// get the table config
$tables = $this->getAllTables();
// make sure it exists
if (!isset($tables->{$tableName})) {
$log->addStep("{$tableName} does not exist in the runtime config. creating empty table", function () use($tables, $tableName) {
$tables->{$tableName} = new BaseObject();
});
}
// make sure we don't have a duplicate entry
if (isset($tables->{$tableName}->{$key})) {
$msg = "Table already contains an entry for '{$key}'";
$log->endAction($msg);
throw new E5xx_ActionFailed(__METHOD__, $msg);
}
// add the entry
$tables->{$tableName}->{$key} = $value;
// save the updated runtime config
$log->addStep("saving runtime config to disk", function () {
$this->st->saveRuntimeConfig();
});
// all done
$log->endAction();
}