cvs: pear /Auth_PrefManager2 PrefManager2.php /Auth_PrefManager2/PrefManager2 Container.php DB.php /Auth_PrefManager2/PrefManager2/Container DB.php
| From: | Jon Wood | Date: | Sun, 04 Jul 2004 15:15:44 +0000 |
| Subject: | cvs: pear /Auth_PrefManager2 PrefManager2.php /Auth_PrefManager2/PrefManager2 Container.php DB.php /Auth_PrefManager2/PrefManager2/Container DB.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-21490@lists.php.net to get a copy of this message | ||
jellybob Sun Jul 4 11:15:44 2004 EDT
Added files:
/pear/Auth_PrefManager2/PrefManager2 Container.php
/pear/Auth_PrefManager2/PrefManager2/Container DB.php
Removed files:
/pear/Auth_PrefManager2/PrefManager2 DB.php
Modified files:
/pear/Auth_PrefManager2 PrefManager2.php
Log:
Restructured the class tree, with Auth_PrefManager2 containing only the
factory and singleton methods, and containers extending
Auth_PrefManager2_Container.
http://cvs.php.net/diff.php/pear/Auth_PrefManager2/PrefManager2.php?r1=1.9&r2=1.10&ty=u Index: pear/Auth_PrefManager2/PrefManager2.php diff -u pear/Auth_PrefManager2/PrefManager2.php:1.9 pear/Auth_PrefManager2/PrefManager2.php:1.10 --- pear/Auth_PrefManager2/PrefManager2.php:1.9 Tue Jun 29 14:41:56 2004 +++ pear/Auth_PrefManager2/PrefManager2.php Sun Jul 4 11:15:44 2004 @@ -1,22 +1,4 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */ -// +----------------------------------------------------------------------+ -// | Copyright (c) 2004 Jon Wood | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 2.02 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | http://www.php.net/license/2_02.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Authors: Jon Wood <jon@jellybob.co.uk> | -// | Paul M. Jones <pmjones@ciaweb.net> | -// +----------------------------------------------------------------------+ -// -// $Id: PrefManager2.php,v 1.9 2004/06/29 18:41:56 jellybob Exp $ - /** * Used for error handling. */ @@ -27,9 +9,6 @@ */ define('AUTH_PREFMANAGER2_CONTAINER_NOT_FOUND', -1); define('AUTH_PREFMANAGER2_NOT_IMPLEMENTED', -2); -define('AUTH_PREFMANAGER2_DB_NO_DSN', -3); -define('AUTH_PREFMANAGER2_DB_CONNECT_FAILED', -4); -define('AUTH_PREFMANAGER2_DB_QUERY_FAILED', -5); /**#@-*/ /** @@ -39,10 +18,7 @@ $GLOBALS['_Auth_PrefManager2']['err'] = array( 'en' => array( AUTH_PREFMANAGER2_CONTAINER_NOT_FOUND => 'The container you requested could not be loaded.', - AUTH_PREFMANAGER2_NOT_IMPLEMENTED => 'This container doesn\'t implement this method.', - AUTH_PREFMANAGER2_DB_NO_DSN => 'You must provide a DSN to connect to.', - AUTH_PREFMANAGER2_DB_CONNECT_FAILED => 'A connection couldn\'t be established with the database.', - AUTH_PREFMANAGER2_DB_QUERY_FAILED => 'A database query failed.' + AUTH_PREFMANAGER2_NOT_IMPLEMENTED => 'This container doesn\'t implement this method.' ) ); } @@ -64,29 +40,6 @@ class Auth_PrefManager2 { /** - * The language to use for error messages.<br /> - * - * Possible values<br /> - * <ul> - * <li><em>en:</em> English</li> - * </ul> - * - * @var string - * @access public - * @since 0.1.0 - */ - var $locale = 'en'; - - /** - * An array of options to use. - * - * @var array - * @access protected - * @since 0.1.0 - */ - var $_options = array(); - - /** * The PEAR_ErrorStack object to use for error handling. * * @var PEAR_ErrorStack @@ -96,23 +49,6 @@ var $_errorStack = null; /** - * Constructor - * - * Applications should never call this constructor directly, instead - * create a container with the factory method. - * - * @access protected - * @param array $options An associative array of options. - * @return void - * @see Auth_PrefManager2::&factory() - */ - function Auth_PrefManager2($options = array()) - { - $this->_errorStack =& PEAR_ErrorStack::singleton('Auth_PrefManager2'); - $this->_parseOptions($options); - } - - /** * Creates an instance of PrefManager, with the options specified, and data * access being done by the specified container. * @@ -129,8 +65,8 @@ */ function &factory($container, $options = array()) { - $class = "Auth_PrefManager2_${container}"; - $file = "Auth/PrefManager2/${container}.php"; + $class = "Auth_PrefManager2_Container_${container}"; + $file = "Auth/PrefManager2/Container/${container}.php"; if (class_exists($class)) { $obj =& new $class($options); @@ -143,7 +79,7 @@ } if ($include) { - $class = "Auth_PrefManager2_${container}"; + $class = "Auth_PrefManager2_Container_${container}"; if (class_exists($class)) { $obj =& new $class($options); return $obj; @@ -159,13 +95,12 @@ } /** - * Returns a reference to an Auth_PrefManager2 object. - * - * A new object will only be created if one doesn't already exist with the - * same container and options. - * + * Returns a concrete PrefManager container, making use of an existing one if + * available. + * * @param string $container The container to use. - * @param array $options An associative array of options to pass to the container. + * @param array $options An associative array of options to pass to the + * container. * @return Auth_PrefManager2 A container, ready to use. * @access public * @static @@ -174,245 +109,16 @@ function &singleton($container, $options = array()) { static $instances; - if (!isset($instances)) { + if (is_null($instances)) { $instances = array(); } - $key = serialize(array($container, $options)); - if (!isset($instances[$key])) { - $instances[$key] =& Auth_PrefManager2::factory($container, $options); - } - - return $instances[$key]; - } - - /** - * 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|null The value, or null of no value was available. - * @access public - */ - function getPref($preference, $owner = null, $application = null, $returnDefaults = true) - { - if (is_null($owner)) { - $owner = $this->_options['default_owner']; - } - - if (is_null($application)) { - $application = $this->_options['default_app']; - } - - if (!is_null($value = $this->_get($owner, $preference, $application))) { - return $this->_decodeValue($value); - } else { - if ($returnDefaults && $options['return_defaults']) { - 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 - * @access public - */ - function setPref($preference, $value, $owner = null, $application = null) - { - if (is_null($owner)) { - $owner = $this->_options['default_owner']; - } - - if (is_null($application)) { - $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 - * @access public - */ - function deletePref($preference, $owner = null, $application = null) - { - if (is_null($owner)) { - $owner = $this->_options['default_owner']; - } - - if (is_null($application)) { - $application = $this->_options['default_app']; - } - - return $this->_delete($owner, $preference, $application = null); - } - - /** - * Sets a value with the container. - * This method should be overridden by container classes to do whatever - * needs doing. - * - * @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 - * @access protected - * @abstract - */ - function _set($owner, $preference, $value, $application) - { - $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); - return false; - } - - /** - * Gets a value from the container. - * This method should be overridden by container classes to do whatever - * needs doing. - * - * @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 - * @access protected - * @abstract - */ - function _get($owner, $preference, $application) - { - $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); - return false; - } - - /** - * Deletes a value from the container. - * This method should be overridden by container classes to do whatever - * needs doing. - * - * @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 - * @access protected - * @abstract - */ - function _delete($owner, $preference, $application) - { - $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); - return false; - } - - /** - * Checks if the specified preference exists in the data container. - * This method should be overridden by container classes to do whatever - * needs doing. - * - * 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? - * @access protected - * @abstract - */ - function _exists($owner, $preference, $application) - { - $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); - return null; - } - - /** - * 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. - * @access protected - */ - function _encodeValue($value) - { - if ($this->_options['serialize']) { - return serialize($value); - } - - return $value; - } - - /** - * 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. - * @access protected - */ - function _decodeValue($value) - { - if ($this->_options['serialize']) { - return unserialize($value); - } - - return $value; - } - - /** - * Reads the options array, and sets default values for anything - * which isn't set. - * - * 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. - * @return void - * @access protected - */ - function _parseOptions($options) - { - if (!isset($options['default_user'])) { - $options['default_user'] = '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; + $hash = serialize(array($container, $options)); + if (!isset($instances[$hash])) { + $instances[$hash] =& Auth_PrefManager2::factory($container, $options); } - $this->_options = $options; + return $instances[$hash]; } /** http://cvs.php.net/co.php/pear/Auth_PrefManager2/PrefManager2/Container.php?r=1.1&p=1 Index: pear/Auth_PrefManager2/PrefManager2/Container.php +++ pear/Auth_PrefManager2/PrefManager2/Container.php <?php class Auth_PrefManager2_Container { /** * An array of options to use. * * @var array * @access protected * @since 0.1.0 */ var $_options = array(); /** * The PEAR_ErrorStack object to use for error handling. * * @var PEAR_ErrorStack * @access protected * @since 0.1.0 */ var $_errorStack = null; /** * Constructor * * Applications should never call this constructor directly, instead * create a container with the factory method. * * @access protected * @param array $options An associative array of options. * @return void * @see Auth_PrefManager2::&factory() */ function Auth_PrefManager2_Common($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|null The value, or null of no value was available. * @access public */ function getPref($preference, $owner = null, $application = null, $returnDefaults = true) { if (is_null($owner)) { $owner = $this->_options['default_owner']; } if (is_null($application)) { $application = $this->_options['default_app']; } if (!is_null($value = $this->_get($owner, $preference, $application))) { return $this->_decodeValue($value); } else { if ($returnDefaults && $options['return_defaults']) { 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 * @access public */ function setPref($preference, $value, $owner = null, $application = null) { if (is_null($owner)) { $owner = $this->_options['default_owner']; } if (is_null($application)) { $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 * @access public */ function deletePref($preference, $owner = null, $application = null) { if (is_null($owner)) { $owner = $this->_options['default_owner']; } if (is_null($application)) { $application = $this->_options['default_app']; } return $this->_delete($owner, $preference, $application = null); } /** * Sets a value with the container. * This method should be overridden by container classes to do whatever * needs doing. * * @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 * @access protected * @abstract */ function _set($owner, $preference, $value, $application) { $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); return false; } /** * Gets a value from the container. * This method should be overridden by container classes to do whatever * needs doing. * * @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 * @access protected * @abstract */ function _get($owner, $preference, $application) { $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); return false; } /** * Deletes a value from the container. * This method should be overridden by container classes to do whatever * needs doing. * * @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 * @access protected * @abstract */ function _delete($owner, $preference, $application) { $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); return false; } /** * Checks if the specified preference exists in the data container. * This method should be overridden by container classes to do whatever * needs doing. * * 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? * @access protected * @abstract */ function _exists($owner, $preference, $application) { $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); return null; } /** * 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. * @access protected */ function _encodeValue($value) { if ($this->_options['serialize']) { return serialize($value); } return $value; } /** * 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. * @access protected */ function _decodeValue($value) { if ($this->_options['serialize']) { return unserialize($value); } return $value; } /** * Reads the options array, and sets default values for anything * which isn't set. * * 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. * @return void * @access protected */ function _parseOptions($options) { if (!isset($options['default_user'])) { $options['default_user'] = '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'; } $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. * @return void * @access protected */ function _throwError($code, $level = 'error', $params = array(), $repackage = null) { $locale = isset($this->_errorMessages['_Auth_PrefManager2'][$this->_options['locale']]) ? $this->_options['locale'] : 'en'; $this->_errorStack->push($code, 'notice', array('name' => $name, 'value' => $value), $GLOBALS['_Auth_PrefManager2'][$locale][$code]); } } ?> http://cvs.php.net/co.php/pear/Auth_PrefManager2/PrefManager2/Container/DB.php?r=1.1&p=1 Index: pear/Auth_PrefManager2/PrefManager2/Container/DB.php +++ pear/Auth_PrefManager2/PrefManager2/Container/DB.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */ // +----------------------------------------------------------------------+ // | Copyright (c) 2004 Jon Wood | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Jon Wood <jon@jellybob.co.uk> | // +----------------------------------------------------------------------+ // // $Id: DB.php,v 1.1 2004/07/04 15:15:44 jellybob Exp $ /** * Require the core class. */ require_once('Auth/PrefManager2/Container.php'); /**#@+ * Error codes */ define('AUTH_PREFMANAGER2_DB_NO_DSN', -3); define('AUTH_PREFMANAGER2_DB_CONNECT_FAILED', -4); define('AUTH_PREFMANAGER2_DB_QUERY_FAILED', -5); /**#@-*/ $_GLOBALS['_Auth_PrefManager2']['err'][AUTH_PREFMANAGER2_DB_NO_DSN] = 'You must provide a DSN to connect to.'; $_GLOBALS['_Auth_PrefManager2']['err'][AUTH_PREFMANAGER2_DB_CONNECT_FAILED] = 'A connection couldn\'t be established with the database.'; $_GLOBALS['_Auth_PrefManager2']['err'][AUTH_PREFMANAGER2_DB_QUERY_FAILED] = 'A database query failed.'; /** * The PEAR DB container for Auth_PrefManager2 * * @author Jon Wood <jon@jellybob.co.uk> * @package Auth_PrefManager2 * @category Authentication */ class Auth_PrefManager2_Container_DB extends Auth_PrefManager2_Container { /** * The DB object being used for data access. * * @access private * @var DB */ var $_db = null; /** * Sets a value with the container. * * @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 * @access protected * @abstract */ function _set($owner, $preference, $value, $application) { if ($this->_exists($owner, $preference, $application)) { // If the preference already exists update its value. $query = sprintf('UPDATE %s SET %s=%s WHERE %s=%s AND %s=%s AND %s=%s', $this->_options['table'], $this->_options['value_column'], $this->_encodeValue($value), $this->_options['owner_column'], DB::quoteSmart($owner), $this->_options['preference_column'], DB::quoteSmart($preference), $this->_options['application_column'], DB::quoteSmart($application)); } else { // Otherwise insert a new row. $query = sprintf('INSERT INTO %s (%s, %s, %s, %s) VALUES(%s, %s, %s, %s)' $this->_options['table'], $this->_options['value_column'], $this->_options['owner_column'], $this->_options['preference_column'], $this->_options['application_column'], $this->_encodeValue($value), DB::quoteSmart($owner), DB::quoteSmart($preference), DB::quoteSmart($application)); } $result = $this->_runQuery($query); if (!is_null($result)) { return true; } return false; } /** * Gets a value from the container. * * @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 mixed|null The value, or null if none is set. * @access protected * @abstract */ function _get($owner, $preference, $application) { if ($this->_exists($owner, $preference, $application)) { // If the preference already exists update its value. $query = sprintf('SELECT %s FROM %s WHERE %s=%s AND %s=%s AND %s=%s', $this->_options['value_column', $this->_options['table'], $this->_options['owner_column'], DB::quoteSmart($owner), $this->_options['preference_column'], DB::quoteSmart($preference), $this->_options['application_column'], DB::quoteSmart($application)); } else { return null; } $result = $this->_runQuery($query); if (!is_null($result)) { $row = $result->fetchRow(); return $row[0]; } return null; } /** * Deletes a value from the container. * * @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 * @access protected * @abstract */ function _delete($owner, $preference, $application) { if ($this->_exists($owner, $preference, $application)) { // If the preference already exists update its value. $query = sprintf('DELETE FROM %s WHERE %s=%s AND %s=%s AND %s=%s', $this->_options['table'], $this->_options['owner_column'], DB::quoteSmart($owner), $this->_options['preference_column'], DB::quoteSmart($preference), $this->_options['application_column'], DB::quoteSmart($application)); } else { // Should this be returning true, since the value is no longer // there, or false, because no delete has been done? return true; } $result = $this->_runQuery($query); if (!is_null($result)) { return true; } return false; } /** * Checks if the specified preference exists in the data container. * * 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? * @access protected * @abstract */ function _exists($owner, $preference, $application) { $query = sprintf('SELECT COUNT(%s) FROM $s WHERE %s=%s AND %s=%s AND %s=%s', $this->_options['owner_column'], $this->_options['table'], $this->_options['owner_column'], DB::smartQuote($owner), $this->_options['preference_column'], DB::smartQuote($preference), $this->_options['application_column'], DB::smartQuote($application)); $result = $this->_runQuery($query); if (!is_null($result)) { $count = $result->fetchRow(); return (bool)$count[0]; } return null; } /** * Connects to the DSN provided in the options array. * * @return bool Success/failure * @throws AUTH_PREFMANAGER2_DB_CONNECTION_FAILED * @access private */ function _connect() { $db =& DB::connect($this->_options['dsn']); if (PEAR::isError($db)) { $this->_throwError(AUTH_PREFMANAGER2_DB_CONNECT_FAILED, 'error', array('dsn' => $this->_options['dsn']), $db); return false; } $this->_db = $db; return true; } /** * Runs a query on the database. * * Returns null on error. * * @param string $query The query to run. * @return DB_Result|null The result object for the query. * @throws AUTH_PREFMANAGER2_DB_QUERY_FAILED * @access private * @todo Improve the connection handling here. */ function &_runQuery($query) { if (is_null($this->_db)) { $this->_connect(); } if (!is_null($this->_db)) { $result = $this->_db->query($query); if (DB::isError($result)) { $this->_throwError(AUTH_PREFMANAGER2_DB_QUERY_FAILED. 'error', array('query' => $query), $result); return null; } return $result; } return null; } /** * 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. * @access protected */ function _encodeValue($value) { return parent::_encodeValue($value); } /** * 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. * @access protected */ function _decodeValue($value) { return parent::_decodeValue($value) } /** * Reads the options array, and sets default values for anything * which isn't set. * * @param array $options An array of options. * @return void * @access protected */ function _parseOptions($options) { if (!isset($options['table'])) { $options['table'] = 'preferences'; } if (!isset($options['owner_column'])) { $options['owner_column'] = 'owner'; } if (!isset($options['application_column'])) { $options['application_column'] = 'application'; } if (!isset($options['preference_column'])) { $options['preference_column'] = 'name'; } if (!isset($options['value_column'])) { $options['value_column'] = 'value'; } if (!isset($options['dsn'])) { $this->_throwError(AUTH_PREFMANAGER2_DB_NO_DSN); } parent::_parseOptions($options); } } ?>
http://cvs.php.net/diff.php/pear/Auth_PrefManager2/PrefManager2.php?r1=1.9&r2=1.10&ty=u Index: pear/Auth_PrefManager2/PrefManager2.php diff -u pear/Auth_PrefManager2/PrefManager2.php:1.9 pear/Auth_PrefManager2/PrefManager2.php:1.10 --- pear/Auth_PrefManager2/PrefManager2.php:1.9 Tue Jun 29 14:41:56 2004 +++ pear/Auth_PrefManager2/PrefManager2.php Sun Jul 4 11:15:44 2004 @@ -1,22 +1,4 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */ -// +----------------------------------------------------------------------+ -// | Copyright (c) 2004 Jon Wood | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 2.02 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | http://www.php.net/license/2_02.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Authors: Jon Wood <jon@jellybob.co.uk> | -// | Paul M. Jones <pmjones@ciaweb.net> | -// +----------------------------------------------------------------------+ -// -// $Id: PrefManager2.php,v 1.9 2004/06/29 18:41:56 jellybob Exp $ - /** * Used for error handling. */ @@ -27,9 +9,6 @@ */ define('AUTH_PREFMANAGER2_CONTAINER_NOT_FOUND', -1); define('AUTH_PREFMANAGER2_NOT_IMPLEMENTED', -2); -define('AUTH_PREFMANAGER2_DB_NO_DSN', -3); -define('AUTH_PREFMANAGER2_DB_CONNECT_FAILED', -4); -define('AUTH_PREFMANAGER2_DB_QUERY_FAILED', -5); /**#@-*/ /** @@ -39,10 +18,7 @@ $GLOBALS['_Auth_PrefManager2']['err'] = array( 'en' => array( AUTH_PREFMANAGER2_CONTAINER_NOT_FOUND => 'The container you requested could not be loaded.', - AUTH_PREFMANAGER2_NOT_IMPLEMENTED => 'This container doesn\'t implement this method.', - AUTH_PREFMANAGER2_DB_NO_DSN => 'You must provide a DSN to connect to.', - AUTH_PREFMANAGER2_DB_CONNECT_FAILED => 'A connection couldn\'t be established with the database.', - AUTH_PREFMANAGER2_DB_QUERY_FAILED => 'A database query failed.' + AUTH_PREFMANAGER2_NOT_IMPLEMENTED => 'This container doesn\'t implement this method.' ) ); } @@ -64,29 +40,6 @@ class Auth_PrefManager2 { /** - * The language to use for error messages.<br /> - * - * Possible values<br /> - * <ul> - * <li><em>en:</em> English</li> - * </ul> - * - * @var string - * @access public - * @since 0.1.0 - */ - var $locale = 'en'; - - /** - * An array of options to use. - * - * @var array - * @access protected - * @since 0.1.0 - */ - var $_options = array(); - - /** * The PEAR_ErrorStack object to use for error handling. * * @var PEAR_ErrorStack @@ -96,23 +49,6 @@ var $_errorStack = null; /** - * Constructor - * - * Applications should never call this constructor directly, instead - * create a container with the factory method. - * - * @access protected - * @param array $options An associative array of options. - * @return void - * @see Auth_PrefManager2::&factory() - */ - function Auth_PrefManager2($options = array()) - { - $this->_errorStack =& PEAR_ErrorStack::singleton('Auth_PrefManager2'); - $this->_parseOptions($options); - } - - /** * Creates an instance of PrefManager, with the options specified, and data * access being done by the specified container. * @@ -129,8 +65,8 @@ */ function &factory($container, $options = array()) { - $class = "Auth_PrefManager2_${container}"; - $file = "Auth/PrefManager2/${container}.php"; + $class = "Auth_PrefManager2_Container_${container}"; + $file = "Auth/PrefManager2/Container/${container}.php"; if (class_exists($class)) { $obj =& new $class($options); @@ -143,7 +79,7 @@ } if ($include) { - $class = "Auth_PrefManager2_${container}"; + $class = "Auth_PrefManager2_Container_${container}"; if (class_exists($class)) { $obj =& new $class($options); return $obj; @@ -159,13 +95,12 @@ } /** - * Returns a reference to an Auth_PrefManager2 object. - * - * A new object will only be created if one doesn't already exist with the - * same container and options. - * + * Returns a concrete PrefManager container, making use of an existing one if + * available. + * * @param string $container The container to use. - * @param array $options An associative array of options to pass to the container. + * @param array $options An associative array of options to pass to the + * container. * @return Auth_PrefManager2 A container, ready to use. * @access public * @static @@ -174,245 +109,16 @@ function &singleton($container, $options = array()) { static $instances; - if (!isset($instances)) { + if (is_null($instances)) { $instances = array(); } - $key = serialize(array($container, $options)); - if (!isset($instances[$key])) { - $instances[$key] =& Auth_PrefManager2::factory($container, $options); - } - - return $instances[$key]; - } - - /** - * 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|null The value, or null of no value was available. - * @access public - */ - function getPref($preference, $owner = null, $application = null, $returnDefaults = true) - { - if (is_null($owner)) { - $owner = $this->_options['default_owner']; - } - - if (is_null($application)) { - $application = $this->_options['default_app']; - } - - if (!is_null($value = $this->_get($owner, $preference, $application))) { - return $this->_decodeValue($value); - } else { - if ($returnDefaults && $options['return_defaults']) { - 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 - * @access public - */ - function setPref($preference, $value, $owner = null, $application = null) - { - if (is_null($owner)) { - $owner = $this->_options['default_owner']; - } - - if (is_null($application)) { - $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 - * @access public - */ - function deletePref($preference, $owner = null, $application = null) - { - if (is_null($owner)) { - $owner = $this->_options['default_owner']; - } - - if (is_null($application)) { - $application = $this->_options['default_app']; - } - - return $this->_delete($owner, $preference, $application = null); - } - - /** - * Sets a value with the container. - * This method should be overridden by container classes to do whatever - * needs doing. - * - * @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 - * @access protected - * @abstract - */ - function _set($owner, $preference, $value, $application) - { - $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); - return false; - } - - /** - * Gets a value from the container. - * This method should be overridden by container classes to do whatever - * needs doing. - * - * @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 - * @access protected - * @abstract - */ - function _get($owner, $preference, $application) - { - $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); - return false; - } - - /** - * Deletes a value from the container. - * This method should be overridden by container classes to do whatever - * needs doing. - * - * @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 - * @access protected - * @abstract - */ - function _delete($owner, $preference, $application) - { - $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); - return false; - } - - /** - * Checks if the specified preference exists in the data container. - * This method should be overridden by container classes to do whatever - * needs doing. - * - * 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? - * @access protected - * @abstract - */ - function _exists($owner, $preference, $application) - { - $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); - return null; - } - - /** - * 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. - * @access protected - */ - function _encodeValue($value) - { - if ($this->_options['serialize']) { - return serialize($value); - } - - return $value; - } - - /** - * 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. - * @access protected - */ - function _decodeValue($value) - { - if ($this->_options['serialize']) { - return unserialize($value); - } - - return $value; - } - - /** - * Reads the options array, and sets default values for anything - * which isn't set. - * - * 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. - * @return void - * @access protected - */ - function _parseOptions($options) - { - if (!isset($options['default_user'])) { - $options['default_user'] = '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; + $hash = serialize(array($container, $options)); + if (!isset($instances[$hash])) { + $instances[$hash] =& Auth_PrefManager2::factory($container, $options); } - $this->_options = $options; + return $instances[$hash]; } /** http://cvs.php.net/co.php/pear/Auth_PrefManager2/PrefManager2/Container.php?r=1.1&p=1 Index: pear/Auth_PrefManager2/PrefManager2/Container.php +++ pear/Auth_PrefManager2/PrefManager2/Container.php <?php class Auth_PrefManager2_Container { /** * An array of options to use. * * @var array * @access protected * @since 0.1.0 */ var $_options = array(); /** * The PEAR_ErrorStack object to use for error handling. * * @var PEAR_ErrorStack * @access protected * @since 0.1.0 */ var $_errorStack = null; /** * Constructor * * Applications should never call this constructor directly, instead * create a container with the factory method. * * @access protected * @param array $options An associative array of options. * @return void * @see Auth_PrefManager2::&factory() */ function Auth_PrefManager2_Common($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|null The value, or null of no value was available. * @access public */ function getPref($preference, $owner = null, $application = null, $returnDefaults = true) { if (is_null($owner)) { $owner = $this->_options['default_owner']; } if (is_null($application)) { $application = $this->_options['default_app']; } if (!is_null($value = $this->_get($owner, $preference, $application))) { return $this->_decodeValue($value); } else { if ($returnDefaults && $options['return_defaults']) { 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 * @access public */ function setPref($preference, $value, $owner = null, $application = null) { if (is_null($owner)) { $owner = $this->_options['default_owner']; } if (is_null($application)) { $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 * @access public */ function deletePref($preference, $owner = null, $application = null) { if (is_null($owner)) { $owner = $this->_options['default_owner']; } if (is_null($application)) { $application = $this->_options['default_app']; } return $this->_delete($owner, $preference, $application = null); } /** * Sets a value with the container. * This method should be overridden by container classes to do whatever * needs doing. * * @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 * @access protected * @abstract */ function _set($owner, $preference, $value, $application) { $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); return false; } /** * Gets a value from the container. * This method should be overridden by container classes to do whatever * needs doing. * * @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 * @access protected * @abstract */ function _get($owner, $preference, $application) { $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); return false; } /** * Deletes a value from the container. * This method should be overridden by container classes to do whatever * needs doing. * * @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 * @access protected * @abstract */ function _delete($owner, $preference, $application) { $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); return false; } /** * Checks if the specified preference exists in the data container. * This method should be overridden by container classes to do whatever * needs doing. * * 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? * @access protected * @abstract */ function _exists($owner, $preference, $application) { $this->_throwError(AUTH_PREFMANAGER2_NOT_IMPLEMENTED); return null; } /** * 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. * @access protected */ function _encodeValue($value) { if ($this->_options['serialize']) { return serialize($value); } return $value; } /** * 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. * @access protected */ function _decodeValue($value) { if ($this->_options['serialize']) { return unserialize($value); } return $value; } /** * Reads the options array, and sets default values for anything * which isn't set. * * 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. * @return void * @access protected */ function _parseOptions($options) { if (!isset($options['default_user'])) { $options['default_user'] = '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'; } $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. * @return void * @access protected */ function _throwError($code, $level = 'error', $params = array(), $repackage = null) { $locale = isset($this->_errorMessages['_Auth_PrefManager2'][$this->_options['locale']]) ? $this->_options['locale'] : 'en'; $this->_errorStack->push($code, 'notice', array('name' => $name, 'value' => $value), $GLOBALS['_Auth_PrefManager2'][$locale][$code]); } } ?> http://cvs.php.net/co.php/pear/Auth_PrefManager2/PrefManager2/Container/DB.php?r=1.1&p=1 Index: pear/Auth_PrefManager2/PrefManager2/Container/DB.php +++ pear/Auth_PrefManager2/PrefManager2/Container/DB.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */ // +----------------------------------------------------------------------+ // | Copyright (c) 2004 Jon Wood | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Jon Wood <jon@jellybob.co.uk> | // +----------------------------------------------------------------------+ // // $Id: DB.php,v 1.1 2004/07/04 15:15:44 jellybob Exp $ /** * Require the core class. */ require_once('Auth/PrefManager2/Container.php'); /**#@+ * Error codes */ define('AUTH_PREFMANAGER2_DB_NO_DSN', -3); define('AUTH_PREFMANAGER2_DB_CONNECT_FAILED', -4); define('AUTH_PREFMANAGER2_DB_QUERY_FAILED', -5); /**#@-*/ $_GLOBALS['_Auth_PrefManager2']['err'][AUTH_PREFMANAGER2_DB_NO_DSN] = 'You must provide a DSN to connect to.'; $_GLOBALS['_Auth_PrefManager2']['err'][AUTH_PREFMANAGER2_DB_CONNECT_FAILED] = 'A connection couldn\'t be established with the database.'; $_GLOBALS['_Auth_PrefManager2']['err'][AUTH_PREFMANAGER2_DB_QUERY_FAILED] = 'A database query failed.'; /** * The PEAR DB container for Auth_PrefManager2 * * @author Jon Wood <jon@jellybob.co.uk> * @package Auth_PrefManager2 * @category Authentication */ class Auth_PrefManager2_Container_DB extends Auth_PrefManager2_Container { /** * The DB object being used for data access. * * @access private * @var DB */ var $_db = null; /** * Sets a value with the container. * * @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 * @access protected * @abstract */ function _set($owner, $preference, $value, $application) { if ($this->_exists($owner, $preference, $application)) { // If the preference already exists update its value. $query = sprintf('UPDATE %s SET %s=%s WHERE %s=%s AND %s=%s AND %s=%s', $this->_options['table'], $this->_options['value_column'], $this->_encodeValue($value), $this->_options['owner_column'], DB::quoteSmart($owner), $this->_options['preference_column'], DB::quoteSmart($preference), $this->_options['application_column'], DB::quoteSmart($application)); } else { // Otherwise insert a new row. $query = sprintf('INSERT INTO %s (%s, %s, %s, %s) VALUES(%s, %s, %s, %s)' $this->_options['table'], $this->_options['value_column'], $this->_options['owner_column'], $this->_options['preference_column'], $this->_options['application_column'], $this->_encodeValue($value), DB::quoteSmart($owner), DB::quoteSmart($preference), DB::quoteSmart($application)); } $result = $this->_runQuery($query); if (!is_null($result)) { return true; } return false; } /** * Gets a value from the container. * * @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 mixed|null The value, or null if none is set. * @access protected * @abstract */ function _get($owner, $preference, $application) { if ($this->_exists($owner, $preference, $application)) { // If the preference already exists update its value. $query = sprintf('SELECT %s FROM %s WHERE %s=%s AND %s=%s AND %s=%s', $this->_options['value_column', $this->_options['table'], $this->_options['owner_column'], DB::quoteSmart($owner), $this->_options['preference_column'], DB::quoteSmart($preference), $this->_options['application_column'], DB::quoteSmart($application)); } else { return null; } $result = $this->_runQuery($query); if (!is_null($result)) { $row = $result->fetchRow(); return $row[0]; } return null; } /** * Deletes a value from the container. * * @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 * @access protected * @abstract */ function _delete($owner, $preference, $application) { if ($this->_exists($owner, $preference, $application)) { // If the preference already exists update its value. $query = sprintf('DELETE FROM %s WHERE %s=%s AND %s=%s AND %s=%s', $this->_options['table'], $this->_options['owner_column'], DB::quoteSmart($owner), $this->_options['preference_column'], DB::quoteSmart($preference), $this->_options['application_column'], DB::quoteSmart($application)); } else { // Should this be returning true, since the value is no longer // there, or false, because no delete has been done? return true; } $result = $this->_runQuery($query); if (!is_null($result)) { return true; } return false; } /** * Checks if the specified preference exists in the data container. * * 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? * @access protected * @abstract */ function _exists($owner, $preference, $application) { $query = sprintf('SELECT COUNT(%s) FROM $s WHERE %s=%s AND %s=%s AND %s=%s', $this->_options['owner_column'], $this->_options['table'], $this->_options['owner_column'], DB::smartQuote($owner), $this->_options['preference_column'], DB::smartQuote($preference), $this->_options['application_column'], DB::smartQuote($application)); $result = $this->_runQuery($query); if (!is_null($result)) { $count = $result->fetchRow(); return (bool)$count[0]; } return null; } /** * Connects to the DSN provided in the options array. * * @return bool Success/failure * @throws AUTH_PREFMANAGER2_DB_CONNECTION_FAILED * @access private */ function _connect() { $db =& DB::connect($this->_options['dsn']); if (PEAR::isError($db)) { $this->_throwError(AUTH_PREFMANAGER2_DB_CONNECT_FAILED, 'error', array('dsn' => $this->_options['dsn']), $db); return false; } $this->_db = $db; return true; } /** * Runs a query on the database. * * Returns null on error. * * @param string $query The query to run. * @return DB_Result|null The result object for the query. * @throws AUTH_PREFMANAGER2_DB_QUERY_FAILED * @access private * @todo Improve the connection handling here. */ function &_runQuery($query) { if (is_null($this->_db)) { $this->_connect(); } if (!is_null($this->_db)) { $result = $this->_db->query($query); if (DB::isError($result)) { $this->_throwError(AUTH_PREFMANAGER2_DB_QUERY_FAILED. 'error', array('query' => $query), $result); return null; } return $result; } return null; } /** * 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. * @access protected */ function _encodeValue($value) { return parent::_encodeValue($value); } /** * 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. * @access protected */ function _decodeValue($value) { return parent::_decodeValue($value) } /** * Reads the options array, and sets default values for anything * which isn't set. * * @param array $options An array of options. * @return void * @access protected */ function _parseOptions($options) { if (!isset($options['table'])) { $options['table'] = 'preferences'; } if (!isset($options['owner_column'])) { $options['owner_column'] = 'owner'; } if (!isset($options['application_column'])) { $options['application_column'] = 'application'; } if (!isset($options['preference_column'])) { $options['preference_column'] = 'name'; } if (!isset($options['value_column'])) { $options['value_column'] = 'value'; } if (!isset($options['dsn'])) { $this->_throwError(AUTH_PREFMANAGER2_DB_NO_DSN); } parent::_parseOptions($options); } } ?>