second step
This commit is contained in:
@@ -1,12 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Config;
|
||||
|
||||
class ContextServiceConfig
|
||||
/**
|
||||
* YAML-backed context configuration.
|
||||
*
|
||||
* This class intentionally has no PHP fallback values. Missing or invalid
|
||||
* configuration must be fixed in config/retriex/*.yaml instead of being hidden
|
||||
* by application defaults.
|
||||
*/
|
||||
final class ContextServiceConfig
|
||||
{
|
||||
//Number of lines included in regular context. Intended for normal conversational continuity.
|
||||
public const MAX_VISIBLE_REGULAR_LINES = 25;
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
*/
|
||||
public function __construct(private readonly array $config)
|
||||
{
|
||||
}
|
||||
|
||||
//Number of lines included in full context. Intended for exceptional or diagnostic scenarios.
|
||||
public const MAX_FULL_LINES = 500;
|
||||
}
|
||||
public function getMaxVisibleRegularLines(): int
|
||||
{
|
||||
return $this->requiredPositiveInt('max_visible_regular_lines');
|
||||
}
|
||||
|
||||
public function getMaxFullLines(): int
|
||||
{
|
||||
return $this->requiredPositiveInt('max_full_lines');
|
||||
}
|
||||
|
||||
private function requiredPositiveInt(string $key): int
|
||||
{
|
||||
if (!array_key_exists($key, $this->config)) {
|
||||
throw new \InvalidArgumentException(sprintf('Missing required RetrieX context config key "%s".', $key));
|
||||
}
|
||||
|
||||
$value = $this->config[$key];
|
||||
|
||||
if (is_int($value)) {
|
||||
$intValue = $value;
|
||||
} elseif (is_string($value) && preg_match('/^-?\d+$/', trim($value)) === 1) {
|
||||
$intValue = (int) trim($value);
|
||||
} else {
|
||||
throw new \InvalidArgumentException(sprintf('RetrieX context config key "%s" must be an integer.', $key));
|
||||
}
|
||||
|
||||
if ($intValue <= 0) {
|
||||
throw new \InvalidArgumentException(sprintf('RetrieX context config key "%s" must be greater than 0.', $key));
|
||||
}
|
||||
|
||||
return $intValue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user