Class: RuntimeSettingsManager

Class for management of the application settings.

Details

This settings manager supports the multistep wizard like processing. That means that you do not have to put all settings in one big form and save them in one action. You can collect them over multiple steps (requests), go forward ad back, validate them on each step and finally save them after the final step.

You do not need any preliminary special settings name definitions. When you introduce a new setting, just start saving and getting it. But you need provide a settings table with a column where the settings data will be saved.

Implements

Authors

Oleg Schildt

Package

Source code

See also

Uses

 

Properties
protected

Internal variable for storing the current context.

protected

Internal variable for storing the dbworker.

protected

Internal variable for storing the array of the settings values.

protected

Internal variable for storing the target column.

protected

Internal variable for storing the target settings table name.

protected

Internal variable for storing the validator.

Methods
public

Returns the current settings context.

public

Returns the value of a settings parameter.

public

Returns the validator for the settings.

public

Initializes the settings manager parameters.

protected

This is internal auxiliary function for loading the settings from the target table defined by the initialization.

public

Loads the settings from the target table.

protected

This is internal auxiliary function for converting the settings to JSON and storing it to the target table defined by the initialization.

public

Saves the settings from to the target table.

public

Sets the settings context.

public

Sets a settings parameter.

public

Sets settings parameters from an array.

public

Sets the validator for the settings.

protected

This is internal auxiliary function for checking that the settings manager is initialized correctly.

public

Validates the current settings values.


Property: RuntimeSettingsManager::$context

protected string $context = "default";

Internal variable for storing the current context.

Type

string

Authors

Oleg Schildt

Source code

See also


Property: RuntimeSettingsManager::$dbworker

protected ?\DatabaseWorkers\DBWorker $dbworker = null;

Internal variable for storing the dbworker.

Type

?\DatabaseWorkers\DBWorker

Authors

Oleg Schildt

Source code


Property: RuntimeSettingsManager::$settings

protected array $settings = [];

Internal variable for storing the array of the settings values.

Type

array

Authors

Oleg Schildt

Source code


Property: RuntimeSettingsManager::$settings_column

protected string $settings_column;

Internal variable for storing the target column.

Type

string

Authors

Oleg Schildt

Source code


Property: RuntimeSettingsManager::$settings_table

protected string $settings_table;

Internal variable for storing the target settings table name.

Type

string

Authors

Oleg Schildt

Source code


Property: RuntimeSettingsManager::$validator

protected ?\Interfaces\ISettingsValidator $validator = null;

Internal variable for storing the validator.

Type

?\Interfaces\ISettingsValidator

Authors

Oleg Schildt

Source code

See also


Method: RuntimeSettingsManager::getContext()

public function getContext(): string;

Returns the current settings context.

Details

Settings might be edited not in one dialog, There can be several masks for different type of settings, or the settings can be configured in a wizard. In this case, only a subset of settings has to be saved and validated. To be able to write a flexible validator for the subsets, the $context is used. It can be - step1, step1, server_settings, db_connection_settings etc.

Returns

string

Returns the current settings context.

Overrides

Authors

Oleg Schildt

Source code

See also


Method: RuntimeSettingsManager::getParameter()

public function getParameter(string $name, mixed|null $default = null): mixed;

Returns the value of a settings parameter.

Parameters

Name Pass type Value type Default value Description
$name by value string

The name of the settings parameter.

$default by value mixed|null null

The default value of the settings parameter if it is not set yet. The parameter is a conformable way to pre-set a parameter to a default value if its value is not set yet.

Returns

mixed

Returns the value of the settings parameter.

Throws

\Exception

It might throw an exception in the case of any errors:

Overrides

Authors

Oleg Schildt

Source code

See also


Method: RuntimeSettingsManager::getValidator()

public function getValidator(): ?\Interfaces\ISettingsValidator;

Returns the validator for the settings.

Returns

?\Interfaces\ISettingsValidator

Returns the validator for the settings or null if none is defined.

Overrides

Authors

Oleg Schildt

Source code

See also


Method: RuntimeSettingsManager::init()

public function init(array $parameters): void;

Initializes the settings manager parameters.

Parameters

Name Pass type Value type Default value Description
$parameters by value array

Settings for saving and loading as an associative array in the form key => value:

  • $parameters["dbworker"] - the dbworker to used for loading and storing settings.

  • $parameters["settings_table"] - the name of the table for the storing of the settings.

  • $parameters["settings_column"] - the name of the column for the storing of the settings.

Returns

void

Throws

\Exception

It might throw an exception in the case of any errors:

Overrides

Authors

Oleg Schildt

Source code


Method: RuntimeSettingsManager::loadJSON()

protected function loadJSON(array &$data): void;

This is internal auxiliary function for loading the settings from the target table defined by the initialization.

Parameters

Name Pass type Value type Default value Description
$data by reference array

The target array with the settings values to be loaded.

Returns

void

Throws

\Exception

It might throw an exception in the case of any errors:

Authors

Oleg Schildt

Source code

See also


Method: RuntimeSettingsManager::loadSettings()

public function loadSettings(): void;

Loads the settings from the target table.

Returns

void

Throws

\Exception

It might throw an exception in the case of any errors:

Overrides

Authors

Oleg Schildt

Source code

See also


Method: RuntimeSettingsManager::saveJSON()

protected function saveJSON(array &$data): void;

This is internal auxiliary function for converting the settings to JSON and storing it to the target table defined by the initialization.

Parameters

Name Pass type Value type Default value Description
$data by reference array

The array with the settings values to be saved.

Returns

void

Throws

\Exception

It might throw an exception in the case of any errors:

Authors

Oleg Schildt

Source code

See also


Method: RuntimeSettingsManager::saveSettings()

public function saveSettings(): void;

Saves the settings from to the target table.

Returns

void

Throws

\Exception

It might throw an exception in the case of any errors:

Overrides

Authors

Oleg Schildt

Source code

See also


Method: RuntimeSettingsManager::setContext()

public function setContext(string $context = "default"): void;

Sets the settings context.

Details

Settings might be edited not in one dialog, There can be several masks for different type of settings, or the settings can be configured in a wizard. In this case, only a subset of settings has to be saved and validated. To be able to write a flexible validator for the subsets, the $context is used. It can be - step1, step1, server_settings, db_connection_settings etc.

Parameters

Name Pass type Value type Default value Description
$context by value string "default"

The settings context.

Returns

void

Overrides

Authors

Oleg Schildt

Source code

See also


Method: RuntimeSettingsManager::setParameter()

public function setParameter(string $name, mixed $value): void;

Sets a settings parameter.

Parameters

Name Pass type Value type Default value Description
$name by value string

The name of the settings parameter.

$value by value mixed

The value of the settings parameter.

Returns

void

Throws

\Exception

It might throw an exception in the case of any errors:

Overrides

Authors

Oleg Schildt

Source code

See also


Method: RuntimeSettingsManager::setParameters()

public function setParameters(array $parameters, bool $force_creation = false): void;

Sets settings parameters from an array.

Parameters

Name Pass type Value type Default value Description
$parameters by value array

Array of parameters in the form key => value.

$force_creation by value bool false

Flag which defines whether the parameter should be created if not exists. If false, only existing parameters are updated.

Returns

void

Throws

\Exception

It might throw an exception in the case of any errors:

  • if some parameters are missing.
  • if dbworker does not extend \SmartFactory\DatabaseWorkers\DBWorker.
  • if the query fails or if some object names are invalid.
  • if the config file is not readable.

Overrides

Authors

Oleg Schildt

Source code

See also


Method: RuntimeSettingsManager::setValidator()

public function setValidator(\SmartFactory\Interfaces\ISettingsValidator $validator): void;

Sets the validator for the settings.

Parameters

Name Pass type Value type Default value Description
$validator by value \SmartFactory\Interfaces\ISettingsValidator

The settings validator.

Returns

void

Overrides

Authors

Oleg Schildt

Source code

See also


Method: RuntimeSettingsManager::validateParameters()

protected function validateParameters(): void;

This is internal auxiliary function for checking that the settings manager is initialized correctly.

Returns

void

Throws

\Exception

It might throw an exception in the case of any errors:

Authors

Oleg Schildt

Source code


Method: RuntimeSettingsManager::validateSettings()

public function validateSettings(): void;

Validates the current settings values.

Details

It should be called after settings the new values of the parameters and before their saving.

Returns

void

Throws

\Exception

It might throw exceptions in the case of any errors.

Overrides

Authors

Oleg Schildt

Source code

See also

Uses