2023-03-19 20:17:24 +00:00
|
|
|
<?php
|
2023-10-21 12:41:39 +00:00
|
|
|
|
2023-03-19 20:17:24 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Dotclear\Plugin\tweakStores;
|
|
|
|
|
2023-10-21 12:41:39 +00:00
|
|
|
/**
|
|
|
|
* @brief tweakStores settings helper.
|
|
|
|
* @ingroup tweakStores
|
|
|
|
*
|
|
|
|
* @author Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2023-03-19 20:17:24 +00:00
|
|
|
class Settings
|
|
|
|
{
|
2023-10-21 12:41:39 +00:00
|
|
|
/**
|
|
|
|
* Enable plugin pacKman behavior.
|
|
|
|
*
|
|
|
|
* @var bool $packman
|
|
|
|
*/
|
2023-03-19 20:17:24 +00:00
|
|
|
public readonly bool $packman;
|
|
|
|
|
2023-10-21 12:41:39 +00:00
|
|
|
/**
|
|
|
|
* Predictable dcstore url.
|
|
|
|
*
|
|
|
|
* @var string $v
|
|
|
|
*/
|
2023-03-19 20:17:24 +00:00
|
|
|
public readonly string $file_pattern;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor set up plugin settings
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2023-07-30 12:53:45 +00:00
|
|
|
$this->packman = (bool) (My::settings()->get('packman') ?? false);
|
|
|
|
$this->file_pattern = (string) (My::settings()->get('file_pattern') ?? '');
|
2023-03-19 20:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overwrite a plugin settings (in db)
|
|
|
|
*
|
|
|
|
* @param string $key The setting ID
|
|
|
|
* @param mixed $value The setting value
|
|
|
|
*
|
2023-10-21 12:41:39 +00:00
|
|
|
* @return bool True on success
|
2023-03-19 20:17:24 +00:00
|
|
|
*/
|
2023-04-29 13:38:22 +00:00
|
|
|
public function set(string $key, mixed $value): bool
|
2023-03-19 20:17:24 +00:00
|
|
|
{
|
|
|
|
if (property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) {
|
2023-07-30 12:53:45 +00:00
|
|
|
My::settings()->drop($key);
|
|
|
|
My::settings()->put($key, $value, gettype($this->{$key}), '', true, true);
|
2023-03-19 20:17:24 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List defined settings keys
|
|
|
|
*
|
2023-10-21 12:41:39 +00:00
|
|
|
* @return array<string, bool|string> The settings keys
|
2023-03-19 20:17:24 +00:00
|
|
|
*/
|
2023-04-29 13:38:22 +00:00
|
|
|
public function dump(): array
|
2023-03-19 20:17:24 +00:00
|
|
|
{
|
2023-04-29 08:51:35 +00:00
|
|
|
return get_object_vars($this);
|
2023-03-19 20:17:24 +00:00
|
|
|
}
|
|
|
|
}
|