Alphred
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download

Namespaces

  • Alphred
  • None

Classes

  • Alfred
  • AppleScript
  • Choose
  • Config
  • Date
  • Dialog
  • Filter
  • Globals
  • i18n
  • Ini
  • Keychain
  • Log
  • Notification
  • Request
  • Result
  • ScriptFilter
  • Text

Interfaces

  • ConfigKeyNotSet
  • Exception
  • FileDoesNotExist
  • InvalidKeychainAccount
  • InvalidScriptFilterArgument
  • InvalidSecurityAction
  • InvalidXMLProperty
  • PasswordExists
  • PasswordNotFound
  • PluginFunctionNotFound
  • RunningOutsideOfAlfred
  • ShouldBeBool
  • TooManyArguments
  • UnknownSecurityException
  • UseOnlyAsStatic

Class Config

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: <pre><span class="php-var">$config</span> = <span class="php-keyword1">new</span> Alphred\Config( <span class="php-quote">'ini'</span> ); <span class="php-var">$config</span>-&gt;set( <span class="php-quote">'username'</span>, <span class="php-quote">'shawn patrick rice'</span> );</pre> To get it later, just use: <pre><span class="php-var">$username</span> = <span class="php-var">$config</span>-&gt;read( <span class="php-quote">'username'</span> );</pre>

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

Namespace: Alphred
Located at Config.php

Methods summary

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

Constructs the Config object

Constructs the Config object

Parameters

$handler
the name of the handler
$filename
the basename of the config file

Since

1.0.0

Todo

Make this pluggable (to load custom handlers)
private boolean
# create_data_directory( )

Creates the data directory

Creates the data directory

Returns

boolean
Whether or not the directory was created or exists

Throws

Alphred\RunningOutsideOfAlfred
private string
# get_config_file( )

Gets the path for the config file

Gets the path for the config file

Returns

string
path to config file

Since

1.0.0
private boolean
# load_handler( string $handler )

Loads a handler

Loads a handler

Parameters

$handler
the name of the handler

Returns

boolean
success of loading the handler

Since

1.0.0
public boolean
# set( string $key, mixed $value )

Sets a value in the config

Sets a value in the config

Parameters

$key
the key to set
$value
the value to set

Returns

boolean
success as true/false

Since

1.0.0
public mixed
# read( string $key )

Reads a value from the config

Reads a value from the config

Parameters

$key
the key to read

Returns

mixed
the values for the key

Since

1.0.0
public boolean
# delete( string $key )

Unsets a value from the config

Unsets a value from the config

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

Parameters

$key
the name of the key

Returns

boolean

Since

1.0.0
private boolean
# load_json( )

Loads the json handler

Loads the json handler

Returns

boolean
success if handler was loaded

Since

1.0.0
private boolean
# set_json( string $key, mixed $value )

Sets a config value

Sets a config value

Parameters

$key
the name of the key
$value
the value of the key

Returns

boolean
success

Since

1.0.0
private mixed
# read_json( string $key )

Reads a config value

Reads a config value

Parameters

$key
the key to read

Returns

mixed
the value of the key

Since

1.0.0
private boolean
# unset_json( string $key )

Unsets a config value

Unsets a config value

Parameters

$key
the key to unset

Returns

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

Since

1.0.0
private boolean
# load_sqlite( )

Loads the SQLite3 handler

Loads the SQLite3 handler

Returns

boolean
true on success

Since

1.0.0
private boolean
# init_db_table( )

Creates the database table

Creates the database table

Returns

boolean
true on success
private boolean
# set_sqlite( string $key, mixed $value, $overwrite = true )

Sets a config value

Sets a config value

Parameters

$key
the name of the key
$value
the value to set
$overwrite

Returns

boolean
success

Since

1.0.0
private mixed
# read_sqlite( string $key )

Reads a config value

Reads a config value

Parameters

$key
the key to read

Returns

mixed
the value of the key

Since

1.0.0
private boolean
# unset_sqlite( string $key )

Deletes a value from the config

Deletes a value from the config

Parameters

$key
the key to delete

Returns

boolean
success

Since

1.0.0
private boolean
# load_ini( )

Loads the ini handler

Loads the ini handler

Returns

boolean
true on success

Since

1.0.0

See

Ini INI functionality
private
# set_ini( string $key, mixed $value )

Sets a config value

Sets a config value

Parameters

$key
the key to set
$value
the value to set

Since

1.0.0

See

Ini INI functionality
private mixed
# read_ini( string $key )

Reads a value from a config file

Reads a value from a config file

Parameters

$key
the key to read

Returns

mixed
the value of the key

Throws

Alphred\ConfigKeyNotSet
when the key is not set

Since

1.0.0

See

Ini INI functionality
private boolean
# unset_ini( string $key )

Unsets a config

Unsets a config

Parameters

$key
the key to unset

Returns

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

Since

1.0.0

See

Ini INI functionality

Magic methods summary

Properties summary

private array $handlers

A list of valid handlers and their file extensions

A list of valid handlers and their file extensions

Current options are json, sqlite, and ini.

Since

1.0.0
# [ // as file_extension => handler_name 'json' => 'json', 'sqlite3' => 'sqlite', 'ini' => 'ini', ]
Alphred API documentation generated by ApiGen