Harden quarantine provisioning; enforce strict permissions and update Ansible and docs
This commit is contained in:
64
core/Config.php
Normal file
64
core/Config.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace UploadLogger\Core;
|
||||
|
||||
/**
|
||||
* Simple immutable configuration holder for the upload logger.
|
||||
*/
|
||||
final class Config
|
||||
{
|
||||
/** @var array<string, mixed> */
|
||||
private array $data;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a module is enabled.
|
||||
*/
|
||||
public function isModuleEnabled(string $name): bool
|
||||
{
|
||||
$modules = $this->data['modules'] ?? [];
|
||||
if (!is_array($modules)) return false;
|
||||
return !empty($modules[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value with optional default.
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
// Support simple dot-notation for nested keys, e.g. "limits.max_size"
|
||||
if (strpos($key, '.') === false) {
|
||||
return $this->data[$key] ?? $default;
|
||||
}
|
||||
|
||||
$parts = explode('.', $key);
|
||||
$cur = $this->data;
|
||||
foreach ($parts as $p) {
|
||||
if (!is_array($cur) || !array_key_exists($p, $cur)) {
|
||||
return $default;
|
||||
}
|
||||
$cur = $cur[$p];
|
||||
}
|
||||
return $cur;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the raw config array.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user