2017-11-08 20:24:49 +01:00
|
|
|
<?php
|
|
|
|
|
2020-10-20 11:47:07 +02:00
|
|
|
namespace Shaarli;
|
|
|
|
|
|
|
|
use Shaarli\Config\ConfigManager;
|
|
|
|
|
2017-11-08 20:24:49 +01:00
|
|
|
/**
|
|
|
|
* Fake ConfigManager
|
|
|
|
*/
|
2020-10-20 11:47:07 +02:00
|
|
|
class FakeConfigManager extends ConfigManager
|
2017-11-08 20:24:49 +01:00
|
|
|
{
|
2017-10-25 23:03:31 +02:00
|
|
|
protected $values = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize with test values
|
|
|
|
*
|
|
|
|
* @param array $values Initial values
|
|
|
|
*/
|
|
|
|
public function __construct($values = [])
|
|
|
|
{
|
|
|
|
$this->values = $values;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a given value
|
|
|
|
*
|
|
|
|
* @param string $key Key of the value to set
|
|
|
|
* @param mixed $value Value to set
|
|
|
|
*/
|
2020-10-20 11:47:07 +02:00
|
|
|
public function set($key, $value, $write = false, $isLoggedIn = false)
|
2017-10-25 23:03:31 +02:00
|
|
|
{
|
|
|
|
$this->values[$key] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a given configuration value
|
|
|
|
*
|
|
|
|
* @param string $key Index of the value to retrieve
|
|
|
|
*
|
|
|
|
* @return mixed The value if set, else the name of the key
|
|
|
|
*/
|
2020-10-20 11:47:07 +02:00
|
|
|
public function get($key, $default = '')
|
2017-11-08 20:24:49 +01:00
|
|
|
{
|
2017-10-25 23:03:31 +02:00
|
|
|
if (isset($this->values[$key])) {
|
|
|
|
return $this->values[$key];
|
|
|
|
}
|
2017-11-08 20:24:49 +01:00
|
|
|
return $key;
|
|
|
|
}
|
2018-05-06 17:12:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a setting exists
|
|
|
|
*
|
|
|
|
* @param string $setting Asked setting, keys separated with dots
|
|
|
|
*
|
|
|
|
* @return bool true if the setting exists, false otherwise
|
|
|
|
*/
|
|
|
|
public function exists($setting)
|
|
|
|
{
|
|
|
|
return array_key_exists($setting, $this->values);
|
|
|
|
}
|
2017-11-08 20:24:49 +01:00
|
|
|
}
|