/usr/share/php/Horde/Prefs/Scope.php is in php-horde-prefs 2.7.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | <?php
/**
* This class provides the storage for a preference scope.
*
* Copyright 2010-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
class Horde_Prefs_Scope implements Iterator, Serializable
{
/**
* Is the object being initialized?
*
* @var boolean
*/
public $init = false;
/**
* The scope name.
*
* @var string
*/
public $scope;
/**
* List of dirty prefs.
*
* @var array
*/
protected $_dirty = array();
/**
* Preferences list. Each preference has the following format:
* <pre>
* [pref_name] => array(
* [d] => (string) Default value
* If not present, 'v' is the default value.
* [l] => (boolean) Locked
* If not present, pref is not locked.
* [v] => (string) Current pref value
* )
*
* For internal storage, if 'l' and 'v' are both not available:
* [pref_name] => (string) Current pref value
* </pre>
*
* @var array
*/
protected $_prefs = array();
/**
* Constructor.
*
* @param string $scope The scope for this set of preferences.
*/
public function __construct($scope)
{
$this->scope = $scope;
}
/**
* Removes a preference entry.
*
* @param string $pref The name of the preference to remove.
*
* @return boolean True if preference was removed.
*/
public function remove($pref)
{
if (!($p = $this->_fromInternal($pref))) {
return false;
}
if (isset($p['d'])) {
$p['v'] = $p['d'];
unset($p['d']);
$this->_toInternal($pref, $p);
$this->setDirty($pref, false);
}
return true;
}
/**
* Sets the value for a preference.
*
* @param string $pref The preference name.
* @param string $val The preference value.
*/
public function set($pref, $val)
{
if ($p = $this->_fromInternal($pref)) {
if ($val != $p['v']) {
if (isset($p['d']) && ($val == $p['d'])) {
unset($p['d']);
} else {
$p['d'] = $p['v'];
}
$p['v'] = $val;
$this->_toInternal($pref, $p);
}
} else {
$this->_toInternal($pref, array('v' => $val));
}
}
/**
* Does a preference exist in this scope?
*
* @return boolean True if the preference exists.
*/
public function exists($pref)
{
return isset($this->_prefs[$pref]);
}
/**
* Returns the value of a preference.
*
* @param string $pref The preference name to retrieve.
*
* @return string The value of the preference, null if it doesn't exist.
*/
public function get($pref)
{
return ($p = $this->_fromInternal($pref))
? $p['v']
: null;
}
/**
* Mark a preference as locked.
*
* @param string $pref The preference name.
* @param boolean $locked Is the preference locked?
*/
public function setLocked($pref, $locked)
{
if ($p = $this->_fromInternal($pref)) {
if ($locked) {
if (!isset($p['l'])) {
$p['l'] = true;
$this->_toInternal($pref, $p);
}
} elseif (isset($p['l'])) {
unset($p['l']);
$this->_toInternal($pref, $p);
}
}
}
/**
* Is a preference locked?
*
* @param string $pref The preference name.
*
* @return boolean Whether the preference is locked.
*/
public function isLocked($pref)
{
return ($p = $this->_fromInternal($pref))
? !empty($p['l'])
: false;
}
/**
* Is a preference's value the default?
*
* @param string $pref The preference name.
*
* @return boolean True if the preference contains the default value.
*/
public function isDefault($pref)
{
return ($p = $this->_fromInternal($pref))
? !isset($p['d'])
: true;
}
/**
* Returns the default value of a preference.
*
* @param string $pref The preference name.
*
* @return string The preference's default value.
*/
public function getDefault($pref)
{
return ($p = $this->_fromInternal($pref))
? (isset($p['d']) ? $p['d'] : $p['v'])
: null;
}
/**
* Get the list of dirty preferences.
*
* @return array The list of dirty preferences.
*/
public function getDirty()
{
return array_keys($this->_dirty);
}
/**
* Is a preference marked dirty?
*
* @param mixed $pref The preference name. If null, will return true if
* scope contains at least one dirty pref.
*
* @return boolean True if the preference is marked dirty.
*/
public function isDirty($pref = null)
{
return is_null($pref)
? !empty($this->_dirty)
: isset($this->_dirty[$pref]);
}
/**
* Set the dirty flag for a preference
*
* @param string $pref The preference name.
* @param boolean $dirty True to mark the pref as dirty.
*/
public function setDirty($pref, $dirty)
{
if ($dirty) {
$this->_dirty[$pref] = true;
} else {
unset($this->_dirty[$pref]);
}
}
/**
*/
protected function _fromInternal($pref)
{
if (!isset($this->_prefs[$pref])) {
return false;
}
return is_array($this->_prefs[$pref])
? $this->_prefs[$pref]
: array('v' => $this->_prefs[$pref]);
}
/**
*/
protected function _toInternal($pref, array $value)
{
if (!isset($value['d']) && !isset($value['l'])) {
$value = $value['v'];
}
$this->_prefs[$pref] = $value;
if (!$this->init) {
$this->setDirty($pref, true);
}
}
/* Iterator methods. */
/**
*/
public function current()
{
return $this->_fromInternal($this->key());
}
/**
*/
public function key()
{
return key($this->_prefs);
}
/**
*/
public function next()
{
return next($this->_prefs);
}
/**
*/
public function rewind()
{
return reset($this->_prefs);
}
/**
*/
public function valid()
{
return !is_null(key($this->_prefs));
}
/* Serializable methods. */
/**
*/
public function serialize()
{
return json_encode(array(
$this->scope,
$this->_prefs
));
}
/**
*/
public function unserialize($data)
{
list($this->scope, $this->_prefs) = json_decode($data, true);
}
}
|