Class for management of the config settings stored in a config JSON file.
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.
| Properties | |
|---|---|
|
protected
|
Internal variable for storing the state whether the config file must exist. |
|
protected
|
Internal variable for storing the current context. |
|
protected
|
Internal variable for storing the salt key if the data should be encrypted before saving. |
|
protected
|
Internal variable for storing the state whether the data should be encrypted before saving. |
|
protected
|
Internal variable that holds the target file path for storing the settings data. |
|
protected
|
Internal variable for storing the array of the settings values. |
|
protected
|
Internal variable for storing the state whether the APCU should be used. |
|
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 file defined by the initialization. |
|
public
|
Loads the settings from the target file. |
|
protected
|
This is internal auxiliary function for converting the settings to JSON and storing it to the target file defined by the initialization. |
|
public
|
Saves the settings from to the target file. |
|
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. |
Internal variable for storing the state whether the config file must exist.
Internal variable for storing the current context.
Internal variable for storing the salt key if the data should be encrypted before saving.
Internal variable for storing the state whether the data should be encrypted before saving.
Internal variable that holds the target file path for storing the settings data.
Internal variable for storing the array of the settings values.
Internal variable for storing the state whether the APCU should be used.
Internal variable for storing the validator.
Returns the current settings context.
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 the current settings context.
Returns the value of a settings parameter.
| Name | Pass type | Value type | Default value | Description |
|---|---|---|---|---|
| $name | by value | string |
The name of the settings parameter. |
|
| $default | by value | mixed | 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 the value of the settings parameter.
It might throw an exception in the case of any errors:
Returns the validator for the settings.
Initializes the settings manager 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:
|
It might throw an exception in the case of any system errors:
This is internal auxiliary function for loading the settings from the target file defined by the initialization.
| Name | Pass type | Value type | Default value | Description |
|---|---|---|---|---|
| $data | by reference | array |
The target array with the settings values to be loaded. |
It might throw an exception in the case of any errors:
Loads the settings from the target file.
Returns true if the settings have been successfully loaded, otherwise false.
It might throw an exception in the case of any errors:
This is internal auxiliary function for converting the settings to JSON and storing it to the target file defined by the initialization.
| Name | Pass type | Value type | Default value | Description |
|---|---|---|---|---|
| $data | by reference | array |
The array with the settings values to be saved. |
It might throw an exception in the case of any errors:
Saves the settings from to the target file.
It might throw an exception in the case of any errors:
Sets the settings context.
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.
| Name | Pass type | Value type | Default value | Description |
|---|---|---|---|---|
| $context | by value | string | "default" |
The settings context. |
Sets a settings parameter.
| 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. |
It might throw an exception in the case of any errors:
Sets settings parameters from an array.
| 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. |
It might throw an exception in the case of any errors:
Sets the validator for the settings.
| Name | Pass type | Value type | Default value | Description |
|---|---|---|---|---|
| $validator | by value | \SmartFactory\Interfaces\ISettingsValidator |
The settings validator. |
This is internal auxiliary function for checking that the settings manager is initialized correctly.
It might throw an exception in the case of any errors:
Validates the current settings values.
It should be called after settings the new values of the parameters and before their saving.
It might throw an exception if the content type oк JSON data is invalid.