\Horde_Prefs

The Horde_Prefs class provides a common abstracted interface into the various preferences storage mediums.

It also includes all of the functions for retrieving, storing, and checking preference values.

Summary

Methods
Properties
Constants
__construct()
getCache()
getUser()
getScope()
getScopeObject()
getStorage()
remove()
removeAll()
setValue()
__set()
getValue()
__get()
setLocked()
isLocked()
isDirty()
getDefault()
isDefault()
retrieve()
changeScope()
store()
cleanup()
offsetExists()
offsetGet()
offsetSet()
offsetUnset()
No public properties found
DEFAULT_SCOPE
_getScope()
_loadScope()
$_cache
$_opts
$_scope
$_scopes
$_storage
N/A
No private methods found
No private properties found
N/A

Constants

DEFAULT_SCOPE

DEFAULT_SCOPE

Properties

$_cache

$_cache : \Horde_Prefs_Cache

Caching object.

Type

\Horde_Prefs_Cache

$_opts

$_opts : array

General library options.

Type

array

$_scope

$_scope : string

String containing the name of the current scope. This is used to differentiate between sets of preferences. By default, preferences belong to this scope.

Type

string

$_scopes

$_scopes : array

Scope list. Keys are scope names, values are Horde_Prefs_Scope objects.

Type

array

$_storage

$_storage : array

The storage driver(s).

Type

array

Methods

__construct()

__construct(string  $scope, mixed  $storage = null, array  $opts = array()) 

Constructor.

Parameters

string $scope

The scope for this set of preferences.

mixed $storage

The storage object(s) to use. Either a single Horde_Prefs_Storage object, or an array of objects.

array $opts

Additional confguration options:

cache - (Horde_Prefs_Cache) The cache driver to use.
        DEFAULT: No caching.
logger - (Horde_Log_Logger) Logging object.
         DEFAULT: NONE
sizecallback - (callback) If set, called when setting a value in the
               backend.
               DEFAULT: NONE
user - (string) The name of the user who owns this set of preferences.
       DEFAULT: NONE

getCache()

getCache() : \Horde_Prefs_Cache_Base

Return the cache object.

Returns

\Horde_Prefs_Cache_Base

Cache object.

getUser()

getUser() : string

Return the user who owns these preferences.

Returns

string —

The user these preferences are for.

getScope()

getScope() : string

Get the current scope.

Returns

string —

The current scope (application).

getScopeObject()

getScopeObject(  $scope = null) : \Horde_Prefs_Scope

Returns the current scope object.

Parameters

$scope

Returns

\Horde_Prefs_Scope

The current scope object.

getStorage()

getStorage() : array

Returns the storage drivers.

Returns

array —

The storage drivers.

remove()

remove(string  $pref = null) 

Removes a preference entry from the $prefs hash.

Parameters

string $pref

The name of the preference to remove. If null, removes all preferences from the current scope.

removeAll()

removeAll() 

Removes all preference entries for the current user from the $prefs hash and the backends.

Throws

\Horde_Prefs_Exception

setValue()

setValue(string  $pref, string  $val, array  $opts = array()) : boolean

Sets the given preference to the specified value if the preference is modifiable.

Parameters

string $pref

The preference name to modify.

string $val

The preference value (UTF-8).

array $opts

Additional options:

  - force: (boolean) If true, will set the value disregarding the
           current locked status of the pref. (@since 2.5.0)
           DEFAULT: false
  - nosave: (boolean) If true, the preference will not be saved to the
            storage backend(s).
            DEFAULT: false

Throws

\Horde_Prefs_Exception

Returns

boolean —

True if the value was successfully set, false on a failure.

__set()

__set(  $name,   $value) 

Shortcut to setValue().

Parameters

$name
$value

getValue()

getValue(string  $pref) : string

Returns the value of the requested preference.

Parameters

string $pref

The preference name.

Returns

string —

The value of the preference (UTF-8), null if it doesn't exist.

__get()

__get(  $name) 

Shortcut to getValue().

Parameters

$name

setLocked()

setLocked(string  $pref,   $bool) 

Mark a preference as locked.

Parameters

string $pref

The preference name.

$bool

isLocked()

isLocked(string  $pref) : boolean

Is a preference locked?

Parameters

string $pref

The preference name.

Returns

boolean —

Whether the preference is locked.

isDirty()

isDirty(string  $pref) : boolean

Is a preference marked dirty?

Parameters

string $pref

The preference name.

Returns

boolean —

True if the preference is marked dirty.

getDefault()

getDefault(string  $pref) : string

Returns the default value of the given preference.

Parameters

string $pref

The name of the preference to get the default for.

Returns

string —

The preference's default value.

isDefault()

isDefault(string  $pref) : boolean

Determines if the current preference value is the default value.

Parameters

string $pref

The name of the preference to check.

Returns

boolean —

True if the preference is the application default value.

retrieve()

retrieve(string  $scope = null) 

Retrieves preferences for the current scope.

Parameters

string $scope

Optional scope specifier - if not present the current scope will be used.

changeScope()

changeScope(string  $scope) 

Changes the current preference scope.

Parameters

string $scope

Scope specifier.

store()

store(boolean  $throw = true) 

Save all dirty prefs to the storage backend.

Parameters

boolean $throw

Throw exception on error? If false, ignores errors. (Since 2.1.0)

cleanup()

cleanup(boolean  $all = false) 

Cleanup (e.g. remove) scope(s).

Parameters

boolean $all

Cleanup all scopes. If false, clean present scope only.

offsetExists()

offsetExists(  $offset) 

Parameters

$offset

offsetGet()

offsetGet(  $offset) 

Parameters

$offset

offsetSet()

offsetSet(  $offset,   $value) 

Parameters

$offset
$value

offsetUnset()

offsetUnset(  $offset) 

Parameters

$offset

_getScope()

_getScope(string  $pref) : mixed

Returns the scope of a preference.

Parameters

string $pref

The preference name.

Returns

mixed —

The scope of the preference, or null if it doesn't exist.

_loadScope()

_loadScope(string  $scope) 

Load a specific preference scope.

Parameters

string $scope

The scope to load.