Auth_PrefManager2
[ class tree: Auth_PrefManager2 ] [ index: Auth_PrefManager2 ] [ all elements ]

Source for file PrefManager2.php

Documentation is available at PrefManager2.php

  1. <?php
  2. /**
  3.  * Used for error handling.
  4.  */
  5. require_once('PEAR/ErrorStack.php');
  6.  
  7. /**#@+
  8.  * Error codes
  9.  */
  10. define('AUTH_PREFMANAGER2_CONTAINER_NOT_FOUND'-1);
  11. define('AUTH_PREFMANAGER2_NOT_IMPLEMENTED'-2);
  12. define('AUTH_PREFMANAGER2_DB_NO_DSN'-3);
  13. define('AUTH_PREFMANAGER2_DB_CONNECT_FAILED'-4);
  14. define('AUTH_PREFMANAGER2_DB_QUERY_FAILED'-5);
  15. /**#@-*/
  16.  
  17. /**
  18. * Internationalised error messages
  19. */
  20. if (!isset($GLOBALS['_Auth_PrefManager2']['err'])) {
  21.     $GLOBALS['_Auth_PrefManager2']['err'= array(
  22.         'en' => array(
  23.             AUTH_PREFMANAGER2_CONTAINER_NOT_FOUND => 'The container you requested could not be loaded.',
  24.             AUTH_PREFMANAGER2_NOT_IMPLEMENTED => 'This container doesn\'t implement this method.',
  25.             AUTH_PREFMANAGER2_DB_NO_DSN => 'You must provide a DSN to connect to.',
  26.             AUTH_PREFMANAGER2_DB_CONNECT_FAILED => 'The database connection couldn\'t be established.',
  27.             AUTH_PREFMANAGER2_DB_QUERY_FAILED => 'A database query failed.'
  28.         )
  29.     );
  30. }
  31.  
  32. /**
  33.  * Auth_PrefManager allows you to store and retrieve preferences from
  34.  * data containers, selecting the default value if none exists for the
  35.  * user you have specified.
  36.  *
  37.  * @author Jon Wood <jon@jellybob.co.uk>
  38.  * @author Paul M. Jones <pmjones@ciaweb.net>
  39.  * @package Auth_PrefManager2
  40.  * @category Authentication
  41.  * @version 0.1.0
  42.  * @static
  43.  * @todo Add caching support.
  44.  */
  45. {    
  46.     /**
  47.      * Creates an instance of PrefManager, with the options specified, and data
  48.      * access being done by the specified container.
  49.      *
  50.      * If your using a custom container you can include it before calling
  51.      * the factory method and it will be used without any further setup.
  52.      *
  53.      * @param string $container The container to use.
  54.      * @param array $options An associative array of options to pass to the
  55.      *                        container.
  56.      * @return Auth_PrefManager2 A container, ready to use.
  57.      * @access public
  58.      * @static
  59.      * @throws AUTH_PREFMANAGER2_CONTAINER_NOT_FOUND
  60.      */
  61.     function &factory($container$options = array())
  62.     {
  63.         $class = "Auth_PrefManager2_Container_${container}";
  64.         $file = "Auth/PrefManager2/Container/${container}.php";
  65.         
  66.         if (!isset($options['debug'])) {
  67.             $options['debug'= false;
  68.         }
  69.         
  70.         if (class_exists($class)) {
  71.             $obj =new $class($options);
  72.             return $obj;
  73.         else {
  74.             if ($options['debug']{
  75.                 $include include_once($file);
  76.             else {
  77.                 $include @include_once($file);
  78.             }
  79.             
  80.             if ($include{
  81.                 $class = "Auth_PrefManager2_Container_${container}";
  82.                 if (class_exists($class)) {
  83.                     $obj =new $class($options);
  84.                     return $obj;
  85.                 }
  86.             }
  87.         }
  88.         
  89.         // Something went wrong if we havn't returned by now.
  90.                           'error',
  91.                           array('container' => $container,
  92.                                 'options' => $options));
  93.     }
  94.     
  95.     /**
  96.      * Returns a concrete PrefManager container, making use of an existing one if
  97.      * available.
  98.      *     
  99.      * @param string $container The container to use.
  100.      * @param array $options An associative array of options to pass to the
  101.      *                        container.
  102.      * @return Auth_PrefManager2 A container, ready to use.
  103.      * @access public
  104.      * @static
  105.      * @throws AUTH_PREFMANAGER2_CONTAINER_NOT_FOUND
  106.      */
  107.     function &singleton($container$options = array())
  108.     {
  109.         static $instances;
  110.         if (is_null($instances)) {
  111.             $instances = array();
  112.         }
  113.         
  114.         $hash serialize(array($container$options));
  115.         if (!isset($instances[$hash])) {
  116.             $instances[$hash=Auth_PrefManager2::factory($container$options);
  117.         }
  118.         
  119.         return $instances[$hash];
  120.     }
  121.     
  122.     /**
  123.      * Throws an error, using the current locale if it exists, or en if it doesn't.
  124.      * 
  125.      * @param int $code The error code.
  126.      * @param string $level The level of the error.
  127.      * @param array $params Any other information to include with the error.
  128.      * @return void 
  129.      * @static
  130.      * @access protected
  131.      */
  132.     function _throwError($code$level 'error'$params = array()$repackage = null)
  133.     {
  134.         //$locale = isset($this->_errorMessages['_Auth_PrefManager2']['en']) ? $this->locale : 'en';
  135.         $locale 'en';
  136.         PEAR_ErrorStack::staticPush('Auth_PrefManager2',
  137.                                     $code
  138.                                     $level,
  139.                                     $params,
  140.                                     $GLOBALS['_Auth_PrefManager2']['err'][$locale][$code],
  141.                                     $repackage);
  142.     }
  143. }
  144. ?>

Documentation generated on Mon, 11 Mar 2019 13:54:06 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.