\AlphredConfig

A simple class to manage configuration for workflows

Currently, there are three handlers that are available: json, sqlite, and ini. These correspond to their obvious data storage types. To use, do something simple like:

$config = new Alphred\Config( 'ini' );
$config->set( 'username', 'shawn patrick rice' );

To get it later, just use:

$username = $config->read( 'username' );

You can store arrays and more complex data with the json and ini handlers. Currently, the SQLite3 handler is a bit primitive.

Summary

Methods
Properties
Constants
__construct()
set()
read()
delete()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
create_data_directory()
get_config_file()
load_handler()
load_json()
set_json()
read_json()
unset_json()
load_sqlite()
init_db_table()
set_sqlite()
read_sqlite()
unset_sqlite()
load_ini()
set_ini()
read_ini()
unset_ini()
$handlers
N/A

Properties

$handlers

$handlers : array

A list of valid handlers and their file extensions

Current options are json, sqlite, and ini.

Type

array

Methods

__construct()

__construct(string  $handler, string  $filename = 'config') 

Constructs the Config object

Parameters

string $handler

the name of the handler

string $filename

the basename of the config file

set()

set(string  $key, mixed  $value) : boolean

Sets a value in the config

Parameters

string $key

the key to set

mixed $value

the value to set

Returns

boolean —

success as true/false

read()

read(string  $key) : mixed

Reads a value from the config

Parameters

string $key

the key to read

Returns

mixed —

the values for the key

delete()

delete(string  $key) : boolean

Unsets a value from the config

Note: I would name this unset, but that's a reserved function name.

Parameters

string $key

the name of the key

Returns

boolean

create_data_directory()

create_data_directory() : boolean

Creates the data directory

Throws

\Alphred\RunningOutsideOfAlfred

Returns

boolean —

Whether or not the directory was created or exists

get_config_file()

get_config_file() : string

Gets the path for the config file

Returns

string —

path to config file

load_handler()

load_handler(string  $handler) : boolean

Loads a handler

Parameters

string $handler

the name of the handler

Returns

boolean —

success of loading the handler

load_json()

load_json() : boolean

Loads the json handler

Returns

boolean —

success if handler was loaded

set_json()

set_json(string  $key, mixed  $value) : boolean

Sets a config value

Parameters

string $key

the name of the key

mixed $value

the value of the key

Returns

boolean —

success

read_json()

read_json(string  $key) : mixed

Reads a config value

Parameters

string $key

the key to read

Returns

mixed —

the value of the key

unset_json()

unset_json(string  $key) : boolean

Unsets a config value

Parameters

string $key

the key to unset

Returns

boolean —

true if the key existed; false if the key did not exist

load_sqlite()

load_sqlite() : boolean

Loads the SQLite3 handler

Returns

boolean —

true on success

init_db_table()

init_db_table() : boolean

Creates the database table

Returns

boolean —

true on success

set_sqlite()

set_sqlite(string  $key, mixed  $value,   $overwrite = true) : boolean

Sets a config value

Parameters

string $key

the name of the key

mixed $value

the value to set

$overwrite

Returns

boolean —

success

read_sqlite()

read_sqlite(string  $key) : mixed

Reads a config value

Parameters

string $key

the key to read

Returns

mixed —

the value of the key

unset_sqlite()

unset_sqlite(string  $key) : boolean

Deletes a value from the config

Parameters

string $key

the key to delete

Returns

boolean —

success

load_ini()

load_ini() : boolean

Loads the ini handler

Returns

boolean —

true on success

set_ini()

set_ini(string  $key, mixed  $value) 

Sets a config value

Parameters

string $key

the key to set

mixed $value

the value to set

read_ini()

read_ini(string  $key) : mixed

Reads a value from a config file

Parameters

string $key

the key to read

Throws

\Alphred\ConfigKeyNotSet

when the key is not set

Returns

mixed —

the value of the key

unset_ini()

unset_ini(string  $key) : boolean

Unsets a config

Parameters

string $key

the key to unset

Returns

boolean —

true if the key existed; false if the key did not exist