Source for file Container.php
Documentation is available at Container.php
require_once('Auth/PrefManager2.php');
class Auth_PrefManager2_Container {
* An array of options to use.
* The PEAR_ErrorStack object to use for error handling.
* Applications should never call this constructor directly, instead
* create a container with the factory method.
* @param array $options An associative array of options.
* @see Auth_PrefManager2::&factory()
function Auth_PrefManager2_Container ($options = array ())
$this->_errorStack = & PEAR_ErrorStack ::singleton ('Auth_PrefManager2');
$this->_parseOptions ($options);
* Gets a preference for the specified owner and application.
* @param string $preference The name of the preference to retrieve.
* @param string $owner The owner to retrieve the preference for.
* @param string $application The application to retrieve from, if left as
* null the default application will be used.
* @param bool $returnDefaults Should a default value be returned if no
* user preference is available?
* @return mixed|nullThe value, or null of no value was available.
function getPref ($preference, $owner = null , $application = null , $returnDefaults = true )
$owner = $this->_options['default_owner'];
$application = $this->_options['default_app'];
if (!is_null($value = $this->_get ($owner, $preference, $application))) {
return $this->_decodeValue ($value);
if ($returnDefaults && $this->_options['return_defaults'] && ($owner != $this->_options['default_app'])) {
return $this->getPref ($preference, null , $application);
* Sets a preference for the specified owner and application.
* @param string $preference The name of the preference to retrieve.
* @param mixed $value The value to set the preference to.
* @param string $owner The owner to retrieve the preference for.
* @param string $application The application to retrieve from, if left as
* null the default application will be used.
* @return bool Success/failure
function setPref ($preference, $value, $owner = null , $application = null )
$owner = $this->_options['default_owner'];
$application = $this->_options['default_app'];
return $this->_set ($owner, $preference, $this->_encodeValue ($value), $application);
* Deletes a preference for the specified owner and application.
* @param string $preference The name of the preference to delete.
* @param string $owner The owner to delete the preference for.
* @param string $application The application to delete from, if left as
* null the default application will be used.
* @return bool Success/failure
function deletePref ($preference, $owner = null , $application = null )
$owner = $this->_options['default_owner'];
$application = $this->_options['default_app'];
return $this->_delete ($owner, $preference, $application);
* Sets a value with the container.
* This method should be overridden by container classes to do whatever
* @param string $owner The owner to set the preference for.
* @param string $preference The name of the preference to set.
* @param string $application The application to set for.
* @return bool Success/failure
function _set ($owner, $preference, $value, $application)
* Gets a value from the container.
* This method should be overridden by container classes to do whatever
* @param string $owner The owner to set the preference for.
* @param string $preference The name of the preference to set.
* @param mixed $value The value to set the preference to.
* @param string $application The application to set for.
* @return bool Success/failure
function _get ($owner, $preference, $application)
* Deletes a value from the container.
* This method should be overridden by container classes to do whatever
* @param string $owner The owner to delete the preference for.
* @param string $preference The name of the preference to delete.
* @param string $application The application to delete from.
* @return bool Success/failure
function _delete ($owner, $preference, $application)
* Checks if the specified preference exists in the data container.
* This method should be overridden by container classes to do whatever
* Returns null if an error occurs.
* @param string $owner The owner to delete the preference for.
* @param string $preference The name of the preference to delete.
* @param string $application The application to delete from.
* @return bool Does the pref exist?
function _exists ($owner, $preference, $application)
* Prepares a value for saving in the data container.
* Containers that override this method should always call
* parent::_encodeValue() to do serialization.
* @param mixed $value The value to prepare.
* @return mixed The prepared value.
function _encodeValue ($value)
if ($this->_options['serialize']) {
* Reverts any preparation that was done to store the value.
* Containers that override this method should always call
* parent::_decodeValue() to do unserialization.
* @param mixed $value The value to decode.
* @return mixed The unprepared value.
function _decodeValue ($value)
if ($this->_options['serialize']) {
* Reads the options array, and sets default values for anything
* Container classes should override this method, set any defaults
* that they need, and then pass the options to parent::_parseOptions().
* @param array $options An array of options.
function _parseOptions ($options)
if (!isset ($options['default_owner'])) {
$options['default_owner'] = 'default';
if (!isset ($options['default_app'])) {
$options['default_app'] = 'default';
if (!isset ($options['serialize'])) {
$options['serialize'] = true;
if (!isset ($options['cache'])) {
$options['cache'] = true;
if (!isset ($options['cache_key'])) {
$options['cache_key'] = '_prefmanager2';
if (!isset ($options['debug'])) {
$options['debug'] = false;
if (!isset ($options['locale'])) {
$options['locale'] = 'en';
if (!isset ($options['return_defaults'])) {
$options['return_defaults'] = true;
$this->_options = $options;
* Throws an error, using the current locale if it exists, or en if it doesn't.
* @param int $code The error code.
* @param string $level The level of the error.
* @param array $params Any other information to include with the error.
function _throwError ($code, $level = 'error', $params = array (), $repackage = null )
$locale = isset ($this->_errorMessages['_Auth_PrefManager2'][$this->_options['locale']])
? $this->_options['locale']
var_dump($this->_errorStack->push ($code,
$GLOBALS['_Auth_PrefManager2']['err'][$locale][$code],
Documentation generated on Mon, 11 Mar 2019 13:54:06 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|