chore: Аннотации к типам

This commit is contained in:
origami11@yandex.ru 2025-10-21 12:00:06 +03:00
parent 09a61244ca
commit 1e27648a12
17 changed files with 217 additions and 81 deletions

View file

@ -5,21 +5,30 @@ use ctiso\File,
Exception;
/**
* Класс реестра
* Класс реестра
* Реестр организован как ассоциативный многомерный массив
* array( 'name1' => parameters1, 'name2' => parameters1, ... )
*
* name1, name2 ... - Имена модулей
* name1, name2 ... - Имена модулей
* parameters1, parameters1 - Массивы с параметрами модуля
* Имя необходимо чтобы потом легко было удалить ненужные ветки дерева
*/
class Settings
{
/** @var array */
public $data = [];
/** @var string */
protected $file;
/** @var string */
protected $format = 'php';
/** @var bool */
protected $is_read = false;
/**
* Конструктор
* @param string $file Путь к файлу
* @param 'php'|'json'|false $format Формат файла
*/
public function __construct ($file = null, $format = false)
{
$fileFormat = ['theme' => 'json'];
@ -33,7 +42,7 @@ class Settings
* Чтение настроек из файла
* @return Boolean
*/
public function read()
public function read(): bool
{
if (!file_exists ($this->file)) {
$this->is_read = true;
@ -59,7 +68,7 @@ class Settings
/**
* Запись ключа в реестр (Реестр это многомерный массив)
*/
public function writeKey(array $key, $value)
public function writeKey(array $key, $value)
{
// assert(count($key) >= 1);
$data = &$this->data;
@ -67,8 +76,8 @@ class Settings
while (count($key) > 1) {
$name = array_shift($key);
$data = &$data[$name];
}
}
// assert(count($key) == 1);
$name = array_shift($key);
if (is_array($value)) {
@ -97,14 +106,20 @@ class Settings
}
/**
* Чтение ключа из реестра
* Чтение ключа из реестра
* @param array $key Путь к значению ключа
* @return mixed
*/
public function readKey(array $key)
{
return $this->readKeyData($key, $this->data);
}
/**
* Чтение ключа из реестра
* @param array $key Путь к значению ключа
* @return mixed
*/
protected function readKeyData(array $key, $data)
{
// assert(count($key) >= 1);
@ -115,8 +130,8 @@ class Settings
} else {
return null;
}
}
}
// assert(count($key) == 1);
$name = array_shift($key);
if (isset($data[$name])) {
@ -131,7 +146,7 @@ class Settings
* @param mixed $key Путь к значению ключа внутри модуля
*/
public function readKeyList(...$key)
{
{
$result = [];
foreach ($this->data as $name => $value) {
$output = $this->readKeyData($key, $value);
@ -142,13 +157,17 @@ class Settings
return $result;
}
public function removeKey($name)
/**
* Удаление ключа из реестра
* @param string $name Имя ключа
*/
public function removeKey($name): void
{
unset($this->data[$name]);
}
public function removeNode(array $key)
public function removeNode(array $key): void
{
$data = &$this->data;
while (count($key) > 1) {
@ -158,11 +177,11 @@ class Settings
$name = array_shift($key);
unset($data[$name]);
}
/**
* Запись настроек в файл (Может переименовать в store)
*
* @param File $file
* @param File $file
* @return void
*/
public function write($file = null)
@ -198,7 +217,7 @@ class Settings
}
/**
* Список модулей/ключей
* Список модулей/ключей
*/
public function getKeys()
{