Documentation

YamlEngine extends Engine
in package

Manages settings stored in the database or file system

Before trying to access a modules' settings, DON'T forget to call Setting::init() before calling getValue() for the first time!

Tags
copyright

CLOUDREXX CMS - CLOUDREXX AG

author

Reto Kohli reto.kohli@comvation.com

author

Manish Thakur manishthakur@cdnsol.com

version
3.0.0
subpackage

core_setting

todo

Edit PHP DocBlocks!

Table of Contents

Properties

$tab_index  : int
Tab counter for the {@see show()} and {@see show_external()}
$arrSettings  : array<string|int, mixed>
The array of currently loaded settings, like array( 'name' => array( 'section' => section, 'group' => group, 'value' => current value, 'type' => element type (text, dropdown, ... [more to come]), 'values' => predefined values (for dropdown), 'ord' => ordinal number (for sorting), ), ... more ... );
$changed  : bool
Changed flag
$filename  : string
Path to the configuration file used as storage location
$group  : string
The group last used to {@see init()} the settings.
$section  : string
The section last used to {@see init()} the settings.
$yamlSettingRepo  : mixed

Methods

add()  : bool
Add a new record to the settings
addToArray()  : mixed
Adds element to array
alter()  : bool
Alter an existing setting entry
changed()  : bool
Returns the current value of the changed flag.
delete()  : bool
Delete one or more records from the File
deleteModule()  : bool
Deletes all entries for the current section
errorHandler()  : bool
Should be called whenever there's a problem with the settings
flush()  : void
Flush the stored settings
getArray()  : array<string|int, mixed>
Returns the settings array for the given section and group
getArraySetting()  : array<string|int, mixed>
Returns the settings array for the given section and group
getGroup()  : group
Get group
getSection()  : string
Get section
getValue()  : mixed
Returns the settings value stored in the object for the name given.
init()  : bool
Initialize the settings entries from the file with key/value pairs for the current section and the given group
isDefined()  : bool
Returns the true or false for given the setting name
load()  : mixed
set()  : bool
Updates a setting
tab_index()  : int
Optionally sets and returns the value of the tab index
update()  : bool
Updates the value for the given name in the settings
updateAll()  : bool
Stores all settings entries present in the $arrSettings object array variable

Properties

$tab_index

Tab counter for the {@see show()} and {@see show_external()}

public int $tab_index = 1
Tags
access

public

$arrSettings

The array of currently loaded settings, like array( 'name' => array( 'section' => section, 'group' => group, 'value' => current value, 'type' => element type (text, dropdown, ... [more to come]), 'values' => predefined values (for dropdown), 'ord' => ordinal number (for sorting), ), ... more ... );

protected array<string|int, mixed> $arrSettings = null
Tags
access

protected

$changed

Changed flag

protected bool $changed = false

This flag is set to true as soon as any change to the settings is detected. It is cleared whenever updateAll() is called.

Tags
access

protected

$filename

Path to the configuration file used as storage location

protected string $filename = null

$group

The group last used to {@see init()} the settings.

protected string $group = null

Defaults to null (ignored).

Tags
access

protected

$section

The section last used to {@see init()} the settings.

protected string $section = null

Defaults to null (which will cause an error in most methods).

Tags
access

protected

Methods

add()

Add a new record to the settings

public add(string $name, string $value[, int $ord = false ][, string $type = 'text' ][, string $values = '' ][, string $group = null ][, bool $flush = true ]) : bool

The class MUST have been initialized by calling init() or getArray() before this method is called. The present $group stored in the class is used as a default. If the current class $group is empty, it MUST be specified in the call.

Parameters
$name : string

The setting name

$value : string

The value

$ord : int = false

The ordinal value for sorting, defaults to 0

$type : string = 'text'

The element type for displaying, defaults to 'text'

$values : string = ''

The values for type 'dropdown', defaults to the empty string

$group : string = null

The optional group

$flush : bool = true

Whether to flush the new setting to the repository.

Return values
bool

True on success, false otherwise

addToArray()

Adds element to array

public addToArray(string $name, string $item) : mixed
Parameters
$name : string
$item : string

alter()

Alter an existing setting entry

public alter(string $name, string $type[, string $values = '' ][, string $group = '' ][, int $ord = 0 ]) : bool

The class MUST have been initialized by calling init() before this method is called.

Parameters
$name : string

The name of an existing setting entry

$type : string

One of the \Cx\Core\Setting\Controller\Setting::TYPE_* constants

$values : string = ''

The type specific values

$group : string = ''

The group to use. If not set or set to an empty string, the existing group will be left untouched.

$ord : int = 0

The ordinal value for sorting. If not set or set to 0, the existing ordinal value will be left untouched.

Return values
bool

True on success, false otherwise

changed()

Returns the current value of the changed flag.

public changed() : bool

If it returns true, you probably want to call updateAll().

Return values
bool

True if values have been changed in memory, false otherwise

delete()

Delete one or more records from the File

public delete([string $name = null ][, string $group = null ]) : bool

For maintenance/update purposes only. At least one of the parameter values must be non-empty. It will fail if both are empty. Mind that in this case, no records will be deleted. Does flush() the currently loaded settings on success.

Parameters
$name : string = null

The optional setting name. Defaults to null

$group : string = null

The optional group. Defaults to null

Return values
bool

True on success, false otherwise

deleteModule()

Deletes all entries for the current section

public deleteModule() : bool

This is for testing purposes only. Use with care! The $section determines the module affected.

Return values
bool

True on success, false otherwise

errorHandler()

Should be called whenever there's a problem with the settings

public errorHandler() : bool

Tries to fix or recreate the settings.

Return values
bool

False, always.

flush()

Flush the stored settings

public flush() : void

Resets the class to its initial state. Does NOT clear the section, however.

getArray()

Returns the settings array for the given section and group

public getArray(mixed $section[, mixed $group = null ]) : array<string|int, mixed>

See init() on how the arguments are used. If the method is called successively using the same $group argument, the current settings are returned without calling init(). Thus, changes made by calling set() will be preserved.

Parameters
$section : mixed

The section

$group : mixed = null

The optional group

Return values
array<string|int, mixed>

The settings array on success, false otherwise

getArraySetting()

Returns the settings array for the given section and group

public getArraySetting() : array<string|int, mixed>
Return values
array<string|int, mixed>

getGroup()

Get group

public getGroup() : group
Return values
group

getSection()

Get section

public getSection() : string
Return values
string

getValue()

Returns the settings value stored in the object for the name given.

public getValue(string $name) : mixed

If the settings have not been initialized (see init()), or if no setting of that name is present in the current set, null is returned.

Parameters
$name : string

The settings name

Return values
mixed

The settings value, if present, null otherwise

init()

Initialize the settings entries from the file with key/value pairs for the current section and the given group

public init(string $section[, string $group = null ][, string $configRepository = null ]) : bool

An empty $group value is ignored. All records with the section are included in this case. Note that all setting names SHOULD be unambiguous for the entire section. If there are two settings with the same name but different $group values, the second one may overwrite the first!

Parameters
$section : string

The section

$group : string = null

The optional group. Defaults to null

$configRepository : string = null

An optional path to the storage location of config files (/config) which shall be used for the engine 'File System'.

Tags
internal

The records are ordered by group ASC, ord ASC, name ASC

Return values
bool

True on success, false otherwise

isDefined()

Returns the true or false for given the setting name

public isDefined(string $name) : bool

If the settings have not been initialized (see init()), or if no setting of that name is present in the current set, false is returned.

Parameters
$name : string

The settings name

Return values
bool

The if setting name is exist returned true, false otherwise

set()

Updates a setting

public set(string $name, string $value) : bool

If the setting name exists and the new value is not equal to the old one, it is updated, and $changed set to true. Otherwise, nothing happens, and false is returned

Parameters
$name : string

The settings name

$value : string

The settings value

Tags
see
init()
see
updateAll()
Return values
bool

True if the value has been changed, false otherwise, null on noop

tab_index()

Optionally sets and returns the value of the tab index

public tab_index([int $tab_index = null ]) : int
Parameters
$tab_index : int = null

The optional new tab index

Return values
int

The current tab index

update()

Updates the value for the given name in the settings

public update(string $name) : bool

The class MUST have been initialized before calling this method using init(), and the new value been set(). Sets $changed to true and returns true if the value has been updated successfully. Note that this method does not work for adding new settings. See add() on how to do this. Also note that the loaded setting is not updated,

Parameters
$name : string

The settings name

Return values
bool

True on successful update or if unchanged, false on failure

updateAll()

Stores all settings entries present in the $arrSettings object array variable

public updateAll() : bool

Returns boolean true if all records were stored successfully, null if nothing changed (noop), false otherwise. Upon success, also resets the $changed class variable to false. The class MUST have been initialized before calling this method using init(), and the new values been set(). Note that this method does not work for adding new settings. See add() on how to do this.

Return values
bool

True on success, null on noop, false otherwise


        
On this page

Search results