Prose\UsingRuntimeTable::removeItem PHP Метод

removeItem() публичный Метод

Removes an item from the runtimeConfig file
public removeItem ( string $key ) : void
$key string The key that we want to remove
Результат void
    public function removeItem($key)
    {
        // get our table name from the constructor
        $tableName = $this->args[0];
        // what are we doing?
        $log = usingLog()->startAction("remove entry '{$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. '{$key}' not removed";
            $log->endAction($msg);
            return;
        }
        // make sure we have an entry to remove
        if (!isset($tables->{$tableName}->{$key})) {
            $msg = "table does not contain an entry for '{$key}'";
            $log->endAction($msg);
            return;
        }
        // remove the entry
        unset($tables->{$tableName}->{$key});
        // remove the table if it's empty
        if (!count(get_object_vars($tables->{$tableName}))) {
            $log->addStep("table '{$tableName}' is empty, removing from runtime config", function () use($tables, $tableName) {
                unset($tables->{$tableName});
            });
        }
        // save the changes
        $this->st->saveRuntimeConfig();
        // all done
        $log->endAction();
    }