PHP Class Habari\Options

Inheritance: extends Singleton
Show file Open project: habari/system Class Usage Examples

Public Methods

Method Description
__get ( string $name ) : mixed Retrieve an option value
__isset ( $name )
__set ( string $name, mixed $value ) Applies the option value to the options table
__unset ( string $name ) Removes an option from the options table
clear_cache ( ) Clears memory of cached options
delete ( string | array $name ) Shortcut to unset an option in the options table
delete_group ( string $prefix ) Delete a group of options with a specific prefix
get ( string | array $name, mixed $default_value = null ) : mixed Shortcut to return the value of an option
get_all_options ( ) Fetch all options from the options table into local storage
get_group ( string $prefix ) : array Fetch a group of options with a specific prefix Useful for plugins that use FormUI to automatically store options with the plugin's prefix.
is_static ( string $name ) : boolean Check if an option was set via the config, making it unsettable
out ( string $name ) Shortcut to output the value of an option
set ( string | array $name, mixed $value = '' ) function set Shortcut to set the value of an option
set_group ( string $prefix, array $values ) Set a group of options with a specific prefix

Protected Methods

Method Description
instance ( ) Enables singleton working properly

Method Details

__get() public method

Retrieve an option value
public __get ( string $name ) : mixed
$name string Name of the option to get
return mixed Stored value for specified option

__isset() public method

public __isset ( $name )

__set() public method

Applies the option value to the options table
public __set ( string $name, mixed $value )
$name string Name of the option to set
$value mixed Value to set

__unset() public method

Removes an option from the options table
public __unset ( string $name )
$name string The name of the option

clear_cache() public static method

Clears memory of cached options
public static clear_cache ( )

delete() public static method

Shortcut to unset an option in the options table
public static delete ( string | array $name )
$name string | array The name of the option or an array of names to delete.

delete_group() public static method

Options::delete_group( 'foo' ); would delete all foo__* option names
public static delete_group ( string $prefix )
$prefix string The prefix to delete

get() public static method

$foo = Options::get('foo'); // returns null if the option 'foo' does not exist list($foo, $bar, $baz) = Options::get( array('foo1', 'bar2', 'baz3') ); // useful with array_keys() $bar = Options::get('foo', 'bar'); // returns 'bar' if the option 'foo' does not exist. useful for avoiding if/then blocks to detect unset options
public static get ( string | array $name, mixed $default_value = null ) : mixed
$name string | array The name or an array of names of the option to fetch.
$default_value mixed The value to return for an option if it does not exist.
return mixed The option requested or an array of requested options, $default_value for each if the option does not exist

get_all_options() public method

Fetch all options from the options table into local storage
public get_all_options ( )

get_group() public static method

Fetch a group of options with a specific prefix Useful for plugins that use FormUI to automatically store options with the plugin's prefix.
public static get_group ( string $prefix ) : array
$prefix string The prefix to fetch
return array An associative array of all options with that prefix

instance() protected static method

Enables singleton working properly
protected static instance ( )

is_static() public static method

Check if an option was set via the config, making it unsettable
public static is_static ( string $name ) : boolean
$name string The name of the option to check
return boolean True if the option is set in the config

out() public static method

Options::out('foo');
public static out ( string $name )
$name string Name of the option to output

set() public static method

Options::set('foo', 'newvalue'); Options::set( array( 'foo' => 'bar', 'baz' => 'qux' ) );
public static set ( string | array $name, mixed $value = '' )
$name string | array Name of the option to set or an array of name => value options to set.
$value mixed New value of the option to store. If first parameter is an array, $value is ignored.

set_group() public static method

Options::set_group( 'foo', array( 'bar' => 'baz', 'qux' => 'quux' ) ); results in 2 options: foo__bar == baz and foo__qux == quux
public static set_group ( string $prefix, array $values )
$prefix string The prefix to set
$values array An associative array of all options to be set with that prefix