[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Horde/Prefs/ -> session.php (source)

   1  <?php
   2  /**
   3   * Preferences storage implementation for PHP's session implementation.
   4   *
   5   * $Horde: framework/Prefs/Prefs/session.php,v 1.32.12.7 2006/05/11 17:13:23 jan Exp $
   6   *
   7   * Copyright 1999-2006 Jon Parise <jon@horde.org>
   8   *
   9   * See the enclosed file COPYING for license information (LGPL). If you
  10   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  11   *
  12   * @author  Jon Parise <jon@horde.org>
  13   * @since   Horde 1.3.4
  14   * @package Horde_Prefs
  15   */
  16  class Prefs_session extends Prefs {
  17  
  18      /**
  19       * Constructs a new session preferences object.
  20       *
  21       * @param string $user      The user who owns these preferences. (Unused)
  22       * @param string $password  The password associated with $user. (Unused)
  23       * @param string $scope     The current preferences scope.
  24       * @param array $params     A hash containing connection parameters.
  25       *                           (Unused)
  26       * @param boolean $caching  Should caching be used? (Unused)
  27       *
  28       */
  29      function Prefs_session($user, $password = '', $scope = '',
  30                             $params = null, $caching = true)
  31      {
  32          if (!Util::extensionExists('session')) {
  33              Horde::fatal(PEAR::raiseError(_("Prefs_session: Required session extension not found."), __FILE__, __LINE__));
  34          }
  35  
  36          $this->_scope = $scope;
  37  
  38          parent::Prefs();
  39      }
  40  
  41      /**
  42       * Retrieves the requested set of preferences from the current session.
  43       *
  44       * @return mixed  True on success or a PEAR_Error object on failure.
  45       */
  46      function retrieve()
  47      {
  48          /* Load defaults to make sure we have all preferences. */
  49          parent::retrieve();
  50  
  51          $global_prefs = array();
  52          $local_prefs = array();
  53  
  54          /* Retrieve global and local preferences from the session variable. */
  55          if (isset($_SESSION['horde_prefs']['horde'])) {
  56              $global_prefs = $_SESSION['horde_prefs']['horde'];
  57          }
  58          if (isset($_SESSION['horde_prefs'][$this->_scope])) {
  59              $local_prefs = $_SESSION['horde_prefs'][$this->_scope];
  60          }
  61  
  62          /* Retrieve and store the local and global preferences. */
  63          $this->_prefs = array_merge($this->_prefs, $global_prefs, $local_prefs);
  64  
  65          /* Call hooks. */
  66          if (!isset($_SESSION['horde_prefs'])) {
  67              $this->_callHooks();
  68          }
  69  
  70          return true;
  71      }
  72  
  73      /**
  74       * Stores preferences in the current session.
  75       *
  76       * @param array $prefs  An array listing the preferences to be stored. If
  77       *                      not specified, store all the preferences listed in
  78       *                      the $prefs hash.
  79       *
  80       * @return mixed  True on success or a PEAR_Error object on failure.
  81       */
  82      function store($prefs = array())
  83      {
  84          /* Create and register the preferences array, if necessary. */
  85          if (!isset($_SESSION['horde_prefs'])) {
  86              $_SESSION['horde_prefs'] = array();
  87          }
  88  
  89          /* Copy the current preferences into the session variable. */
  90          foreach ($this->_prefs as $name => $pref) {
  91              $scope = $this->getScope($name);
  92              $_SESSION['horde_prefs'][$scope][$name] = $pref;
  93          }
  94  
  95          return true;
  96      }
  97  
  98      /**
  99       * Perform cleanup operations.
 100       *
 101       * @param boolean $all  Cleanup all Horde preferences.
 102       */
 103      function cleanup($all = false)
 104      {
 105          /* Perform a Horde-wide cleanup? */
 106          if ($all) {
 107              unset($_SESSION['horde_prefs']);
 108          } else {
 109              unset($_SESSION['horde_prefs'][$this->_scope]);
 110              $_SESSION['horde_prefs']['_filled'] = false;
 111          }
 112  
 113          parent::cleanup($all);
 114      }
 115  
 116  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7