getValue() public method

Returns the value of the requested preference.
public getValue ( string $pref ) : string
$pref string The preference name.
return string The value of the preference (UTF-8), null if it doesn't exist.
Esempio n. 1
0
 /**
  * Returns a property from one of the identities. If this value doesn't
  * exist or is locked, the property is retrieved from the prefs backend.
  *
  * @param string $key        The property to retrieve.
  * @param integer $identity  The identity to retrieve the property from.
  *
  * @return mixed  The value of the property.
  */
 public function getValue($key, $identity = null)
 {
     if (is_null($identity) || !isset($this->_identities[$identity])) {
         $identity = $this->_default;
     }
     return !isset($this->_identities[$identity][$key]) || $this->_prefs->isLocked($key) ? $this->_prefs->getValue($key) : $this->_identities[$identity][$key];
 }
Esempio n. 2
0
 /**
  * Upgrades the given preferences from the old H3 way of storing
  * serialized data.
  * OLD method: convert charset, serialize, store.
  * NEW method: serialize, convert charset, store.
  *
  * @param Horde_Prefs $prefs_ob  The preferences object.
  * @param array $names           The list of names to upgrade.
  */
 public function upgradeSerialized($prefs_ob, array $names)
 {
     /* Only do upgrade for SQL driver. */
     foreach ($prefs_ob->getStorage() as $storage) {
         if ($storage instanceof Horde_Prefs_Storage_Sql) {
             break;
         }
     }
     if (!$storage instanceof Horde_Prefs_Storage_Sql) {
         return;
     }
     /* Only do upgrade if charset is not UTF-8. */
     $charset = $storage->getCharset();
     if (strcasecmp($charset, 'UTF-8') === 0) {
         return;
     }
     foreach ($names as $name) {
         if (!$prefs_ob->isDefault($name)) {
             $data = $prefs_ob->getValue($name);
             /* Need to convert only if unserialize fails. If it succeeds,
              * the data has already been converted or there is no need
              * to convert. */
             if (@unserialize($data) === false) {
                 /* Re-convert to original charset. */
                 $data = Horde_String::convertCharset($data, 'UTF-8', $charset);
                 /* Unserialize. If we fail here, remove the value
                  * outright since it is invalid and can not be fixed. */
                 if (($data = @unserialize($data)) !== false) {
                     $data = Horde_String::convertCharset($data, $charset, 'UTF-8');
                     /* Re-save in the prefs backend in the new format. */
                     $prefs_ob->setValue($name, serialize($data));
                 }
             }
         }
     }
 }