@ 2014-07-30T04:13:51Z <?php
/**
* This is a proxy class for calling PrefsManager methods using a fixed
* user ID.
*
* @package ManipleCore_Prefs
*/
class ManipleCore_Prefs_UserPrefs
{
/**
* @var ManipleCore_Prefs_PrefManagerInterface
*/
protected $_prefManager;
/**
* @var array
*/
protected $_prefNames;
/**
* @var int|string
*/
protected $_userId;
/**
* Constructor.
*
* @param ManipleCore_Prefs_PrefManagerInterface $prefsManager
* @param int|string $userId
* @param bool|string $load
*/
public function __construct(ManipleCore_Prefs_PrefManagerInterface $prefManager, $userId, $load = true)
{
if (!is_int($userId) && !is_string($userId)) {
throw new InvalidArgumentException('User ID must either be an integer or a string');
}
$this->_prefManager = $prefManager;
$this->_userId = $userId;
if ($load) {
$prefix = is_string($load) ? $load : null;
$names = $this->_prefManager->loadUserPrefs($userId, $prefix);
$this->_prefNames = array_flip($names);
}
}
/**
* Get user preference.
*
* @param string $name
* @param mixed $defaultValue
* @return mixed
*/
public function get($name, $defaultValue = null)
{
$value = $this->_prefManager->getUserPref($this->_userId, $name, $defaultValue);
$this->_prefNames[(string) $name] = true;
return $value;
}
/**
* @param string $name
* @param bool $defaultValue OPTIONAL
* @return bool|null
*/
public function getBool($name, $defaultValue = null)
{
$value = $this->get($name, $defaultValue);
if ($value !== null) {
$value = (bool) $value;
}
return $value;
}
/**
* @param string $name
* @param int $defaultValue OPTIONAL
* @return int|null
*/
public function getInt($name, $defaultValue = null)
{
$value = $this->get($name, $defaultValue);
if ($value !== null) {
$value = (int) $value;
}
return $value;
}
/**
* @param string $name
* @param float $defaultValue OPTIONAL
* @return float|null
*/
public function getFloat($name, $defaultValue = null)
{
$value = $this->get($name, $defaultValue);
if ($value !== null) {
$value = (float) $value;
}
return $value;
}
/**
* @param string $name
* @param string $defaultValue OPTIONAL
* @return string|null
*/
public function getString($name, $defaultValue = null)
{
$value = $this->get($name, $defaultValue);
if ($value !== null) {
$value = (string) $value;
}
return $value;
}
/**
* Set user preference.
*
* @param string $name
* @param mixed $value
* @return ManipleCore_Prefs_UserPrefs
*/
public function set($name, $value)
{
$this->_prefManager->setUserPref($this->_userId, $name, $value);
$this->_prefNames[(string) $name] = true;
return $this;
}
/**
* Reset user preference.
*
* @param string $name
* @return ManipleCore_Prefs_UserPrefs
*/
public function reset($name)
{
$this->_prefManager->resetUserPref($this->_userId, $name);
unset($this->_prefNames[(string) $name]);
return $this;
}
/**
* Persist user preferences.
*
* @return ManipleCore_Prefs_UserPrefs
*/
public function save()
{
$this->_prefManager->saveUserPrefs($this->_userId);
return $this;
}
/**
* Return names of loaded preferences.
*
* @return string[]
*/
public function getNames()
{
return array_keys((array) $this->_prefNames);
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.8 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.20 , 7.2.0 - 7.2.33 , 7.3.12 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Output for 4.4.2 - 4.4.9 Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/TVNJI on line 14
Process exited with code 255 . Output for 4.3.0 - 4.3.1 , 4.3.5 - 4.3.11 , 4.4.0 - 4.4.1 Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/TVNJI on line 14
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/TVNJI on line 14
Process exited with code 255 . preferences:dark mode live preview
187.29 ms | 401 KiB | 313 Q