\Sam_Driver_Base

Sam_Driver_Base defines an API for implementing storage backends for Sam.

Summary

Methods
Properties
Constants
__construct()
retrieve()
store()
hasCapability()
booleanToOption()
optionToBoolean()
getOption()
setOption()
getListOption()
setListOption()
setStackedOption()
No public properties found
No constants found
No protected methods found
$_options
$_defaults
$_user
$_capabilities
$_params
N/A
No private methods found
No private properties found
N/A

Properties

$_options

$_options : array

The user's preferences.

Type

array

$_defaults

$_defaults : array

The defaults to use if user hasn't defined a value.

Type

array

$_user

$_user : string

The user name.

Type

string

$_capabilities

$_capabilities : array

Capabilities supported by the driver.

Type

array

$_params

$_params : array

Parameter hash for the backend.

Type

array

Methods

__construct()

__construct(string  $user, array  $params = array()) 

Constructor.

Parameters

string $user

A user name.

array $params

Backend specific class parameters.

retrieve()

retrieve() 

Retrieves user preferences and optionally default values from the backend.

Throws

\Sam_Exception

store()

store(boolean  $defaults = false) 

Stores user preferences and optionally default values in the backend.

Parameters

boolean $defaults

Whether to store the global defaults instead of user options.

Throws

\Sam_Exception

hasCapability()

hasCapability(string  $capability) : boolean

Check to see if the backend supports a particular capability.

Parameters

string $capability

The name of the capability to check.

Returns

boolean —

True if the backend is capable, false otherwise.

booleanToOption()

booleanToOption(boolean  $boolean) : mixed

Converts a boolean option to a backend specific value.

Parameters

boolean $boolean

The value to convert.

Returns

mixed —

1 if true and 0 if false.

optionToBoolean()

optionToBoolean(mixed  $option) : boolean

Convert a backend specific boolean value to a PHP boolean.

Parameters

mixed $option

The value to convert.

Returns

boolean —

True if the backend-specific value is true, false otherwise.

getOption()

getOption(string  $option) : mixed

Returns a preference from user settings or global defaults.

Parameters

string $option

The option to retrieve.

Returns

mixed —

The requested option value.

setOption()

setOption(string  $option, string  $value, boolean  $defaults = false) 

Sets a preference value for the user or as global defaults, depending on the parameters.

Does not automatically store options to the backend.

Parameters

string $option

The option to set.

string $value

The new value.

boolean $defaults

Whether to set the global defaults instead of user options.

getListOption()

getListOption(string  $option) : string

Returns an internal address array as a new-line separated string.

Useful for retrieving whitelists and blacklists.

Parameters

string $option

The option to retrieve.

Returns

string —

New-line separated list value.

setListOption()

setListOption(string  $option, string  $value, boolean  $defaults = false) 

Sets an internal address array.

Useful for whitelists and blacklists. The passed data is split at whitespace. Does not automatically store options to the backend.

Parameters

string $option

The option to set.

string $value

A string of data that will be converted to an array and stored for later storage to the backend.

boolean $defaults

Whether to set the global defaults instead of user options.

setStackedOption()

setStackedOption(string  $option, string  $value, boolean  $defaults = false) 

Sets an internal array of options which have multiple elements of data stored in their value.

E.g. rewrite_header takes two elements, a header and a string, as in 'rewrite_header' => 'Subject SPAM'.

There can be multiple entries for these options, so they cannot be treated independently.

Does not automatically store options to the backend.

Parameters

string $option

The base option to set. Should only be 'rewrite_header' ATM.

string $value

A string of data that will be converted to an array and stored for later storage to the backend.

boolean $defaults

Whether to set the global defaults instead of user options.