Prose\UsingRuntimeTable::removeItemFromGroup PHP Method

removeItemFromGroup() public method

Removes an item from the runtimeConfig file
public removeItemFromGroup ( $group, string $key ) : void
$key string The key that we want to remove
return void
    public function removeItemFromGroup($group, $key)
    {
        // get our table name from the constructor
        $tableName = $this->args[0];
        // what are we doing?
        $log = usingLog()->startAction("remove entry '{$group}->{$key}' from {$tableName} table");
        // get the table config
        $tables = $this->getAllTables();
        // make sure it exists
        if (!isset($tables->{$tableName})) {
            $msg = "table is empty / does not exist. '{$group}->{$key}' not removed";
            $log->endAction($msg);
            return;
        }
        if (!isset($tables->{$tableName}->{$group})) {
            $msg = "table has no group '{$group}'. '{$group}->{$key}' not removed";
            $log->endAction($msg);
            return;
        }
        if (!isset($tables->{$tableName}->{$group}->{$key})) {
            $msg = "table does not contain an entry for '{$group}->{$key}'";
            $log->endAction($msg);
            return;
        }
        // remove the entry
        unset($tables->{$tableName}->{$group}->{$key});
        // remove the table if it's empty
        if (!count(get_object_vars($tables->{$tableName}->{$group}))) {
            $log->addStep("table group '{$tableName}->{$group}' is empty, removing from runtime config", function () use($tables, $tableName, $group) {
                unset($tables->{$tableName}->{$group});
            });
        }
        // save the changes
        $this->st->saveRuntimeConfig();
        // all done
        $log->endAction();
    }