1
1
Fork 0

minor fixing: phpdoc & type-hint

This commit is contained in:
Philipp Holzer 2019-07-14 22:31:53 +02:00
parent a2c6240da0
commit b48c22dc1a
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
3 changed files with 73 additions and 22 deletions

View file

@ -25,7 +25,7 @@ class ConfigCache
* @param array $config A initial config array
* @param bool $hidePasswordOutput True, if cache variables should take extra care of password values
*/
public function __construct(array $config = [], $hidePasswordOutput = true)
public function __construct(array $config = [], bool $hidePasswordOutput = true)
{
$this->hidePasswordOutput = $hidePasswordOutput;
$this->load($config);
@ -38,7 +38,7 @@ class ConfigCache
* @param array $config
* @param bool $overwrite Force value overwrite if the config key already exists
*/
public function load(array $config, $overwrite = false)
public function load(array $config, bool $overwrite = false)
{
$categories = array_keys($config);
@ -68,7 +68,7 @@ class ConfigCache
*
* @return null|mixed Returns the value of the Config entry or null if not set
*/
public function get($cat, $key = null)
public function get(string $cat, string $key = null)
{
if (isset($this->config[$cat][$key])) {
return $this->config[$cat][$key];
@ -82,14 +82,14 @@ class ConfigCache
/**
* Sets a default value in the config cache. Ignores already existing keys.
*
* @param string $cat Config category
* @param string $k Config key
* @param mixed $v Default value to set
* @param string $cat Config category
* @param string $key Config key
* @param mixed $value Default value to set
*/
private function setDefault($cat, $k, $v)
private function setDefault(string $cat, string $key, $value)
{
if (!isset($this->config[$cat][$k])) {
$this->set($cat, $k, $v);
if (!isset($this->config[$cat][$key])) {
$this->set($cat, $key, $value);
}
}
@ -102,7 +102,7 @@ class ConfigCache
*
* @return bool True, if the value is set
*/
public function set($cat, $key, $value)
public function set(string $cat, string $key, $value)
{
if (!isset($this->config[$cat])) {
$this->config[$cat] = [];
@ -111,7 +111,7 @@ class ConfigCache
if ($this->hidePasswordOutput &&
$key == 'password' &&
is_string($value)) {
$this->config[$cat][$key] = new HiddenString((string) $value);
$this->config[$cat][$key] = new HiddenString((string)$value);
} else {
$this->config[$cat][$key] = $value;
}
@ -126,7 +126,7 @@ class ConfigCache
*
* @return bool true, if deleted
*/
public function delete($cat, $key)
public function delete(string $cat, string $key)
{
if (isset($this->config[$cat][$key])) {
unset($this->config[$cat][$key]);

View file

@ -20,9 +20,9 @@ class PConfigCache
private $hidePasswordOutput;
/**
* @param bool $hidePasswordOutput True, if cache variables should take extra care of password values
* @param bool $hidePasswordOutput True, if cache variables should take extra care of password values
*/
public function __construct($hidePasswordOutput = true)
public function __construct(bool $hidePasswordOutput = true)
{
$this->hidePasswordOutput = $hidePasswordOutput;
}
@ -34,7 +34,7 @@ class PConfigCache
* @param int $uid
* @param array $config
*/
public function load($uid, array $config)
public function load(int $uid, array $config)
{
$categories = array_keys($config);
@ -56,13 +56,13 @@ class PConfigCache
/**
* Retrieves a value from the user config cache
*
* @param int $uid User Id
* @param string $cat Config category
* @param string $key Config key
* @param int $uid User Id
* @param string $cat Config category
* @param string $key Config key
*
* @return null|string The value of the config entry or null if not set
*/
public function get($uid, $cat, $key = null)
public function get(int $uid, string $cat, $key = null)
{
if (isset($this->config[$uid][$cat][$key])) {
return $this->config[$uid][$cat][$key];
@ -85,7 +85,7 @@ class PConfigCache
*
* @return bool Set successful
*/
public function set($uid, $cat, $key, $value)
public function set(int $uid, string $cat, string $key, $value)
{
if (!isset($this->config[$uid]) || !is_array($this->config[$uid])) {
$this->config[$uid] = [];
@ -98,7 +98,7 @@ class PConfigCache
if ($this->hidePasswordOutput &&
$key == 'password' &&
!empty($value) && is_string($value)) {
$this->config[$uid][$cat][$key] = new HiddenString((string) $value);
$this->config[$uid][$cat][$key] = new HiddenString((string)$value);
} else {
$this->config[$uid][$cat][$key] = $value;
}
@ -116,7 +116,7 @@ class PConfigCache
*
* @return bool true, if deleted
*/
public function delete($uid, $cat, $key)
public function delete(int $uid, string $cat, string $key)
{
if (isset($this->config[$uid][$cat][$key])) {
unset($this->config[$uid][$cat][$key]);

View file

@ -42,8 +42,59 @@ abstract class Configuration
return $this->configCache;
}
/**
* @brief Loads all configuration values of family into a cached storage.
*
* All configuration values of the system are stored in the cache ( @see IConfigCache )
*
* @param string $cat The category of the configuration value
*
* @return void
*/
abstract public function load(string $cat = 'config');
/**
* @brief Get a particular user's config variable given the category name
* ($cat) and a $key.
*
* Get a particular config value from the given category ($cat)
* and the $key from a cached storage either from the $this->configAdapter
* (@see IConfigAdapter ) or from the $this->configCache (@see IConfigCache ).
*
* @param string $cat The category of the configuration value
* @param string $key The configuration key to query
* @param mixed $default_value optional, The value to return if key is not set (default: null)
* @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false)
*
* @return mixed Stored value or null if it does not exist
*/
abstract public function get(string $cat, string $key, $default_value = null, bool $refresh = false);
/**
* @brief Sets a configuration value for system config
*
* Stores a config value ($value) in the category ($cat) under the key ($key)
*
* Note: Please do not store booleans - convert to 0/1 integer values!
*
* @param string $cat The category of the configuration value
* @param string $key The configuration key to set
* @param mixed $value The value to store
*
* @return bool Operation success
*/
abstract public function set(string $cat, string $key, $value);
/**
* @brief Deletes the given key from the system configuration.
*
* Removes the configured value from the stored cache in $this->configCache
* (@see ConfigCache ) and removes it from the database (@see IConfigAdapter ).
*
* @param string $cat The category of the configuration value
* @param string $key The configuration key to delete
*
* @return bool
*/
abstract public function delete(string $cat, string $key);
}