Files

1 line
12 KiB
JSON
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"repo": "asneep22/copilot", "files": {"src/classes/config/config.php": {"b635b604ac27246f8fb8483d2dc78edfb27b82a6": {"t": 1785745777.9388123, "n": 5364, "h": "82f54577d0ce95c4", "c": "<?php\n\ndeclare(strict_types=1);\n\nclass Config\n{\n private static ?array $cache = null;\n private static string $envFile;\n\n public static function init(string $envFile = null): void\n {\n if ($envFile === null) {\n // Попытка найти .env в разных местах\n $possiblePaths = [\n __DIR__ . '/../../.env', // Относительно src/classes/config/\n '/var/www/html/.env', // В Docker контейнере\n __DIR__ . '/../../../.env', // Альтернативный путь\n ];\n \n foreach ($possiblePaths as $path) {\n if (file_exists($path)) {\n $envFile = $path;\n break;\n }\n }\n \n if ($envFile === null) {\n $envFile = __DIR__ . '/../../.env'; // По умолчанию\n }\n }\n self::$envFile = $envFile;\n self::loadEnv();\n }\n\n private static function loadEnv(): void\n {\n if (self::$cache !== null) {\n return;\n }\n\n self::$cache = [];\n\n if (!file_exists(self::$envFile)) {\n error_log(\"[Config] .env file not found: \" . self::$envFile);\n return;\n }\n\n $lines = file(self::$envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);\n foreach ($lines as $line) {\n $line = trim($line);\n if (str_starts_with($line, '#')) {\n continue;\n }\n\n $parts = explode('=', $line, 2);\n if (count($parts) === 2) {\n $key = trim($parts[0]);\n $value = trim($parts[1]);\n // Удаляем кавычки, если они есть\n if ((str_starts_with($value, '\"') && str_ends_with($value, '\"')) ||\n (str_starts_with($value, \"'\") && str_ends_with($value, \"'\"))) {\n $value = substr($value, 1, -1);\n }\n self::$cache[$key] = $value;\n }\n }\n }\n\n public static function get(string $key, string $default = ''): string\n {\n if (self::$cache === null) {\n self::init();\n }\n\n return self::$cache[$key] ?? getenv($key) ?: $default;\n }\n\n public static function getInt(string $key, int $default = 0): int\n {\n $value = self::get($key, (string)$default);\n return (int)$value;\n }\n\n public static function getArray(string $key, string $separator = ','): array\n {\n $value = self::get($key, '');\n error_log(\"[Config] getArray('{$key}') raw value: '\" . addslashes($value) . \"' (length: \" . strlen($value) . \")\");\n \n if (empty($value)) {\n error_log(\"[Config] getArray('{$key}') returned empty array\");\n return [];\n }\n \n $result = array_map('trim', explode($separator, $value));\n $result = array_filter($result, function($item) {\n return !empty($item);\n });\n \n // Дополнительная очистка: удаляем запятые в начале/конце каждого элемента\n $result = array_map(function($item) {\n return trim($item, \" \\t\\n\\r\\0\\x0B,\");\n }, $result);\n $result = array_filter($result, function($item) {\n return !empty($item);\n });\n \n error_log(\"[Config] getArray('{$key}') parsed to \" . count($result) . \" items: \" . json_encode($result, JSON_UNESCAPED_UNICODE));\n return array_values($result);\n }\n\n public static function getMcpServers(): array\n {\n $servers = self::getArray('MCP_SERVERS');\n error_log(\"[Config] getMcpServers() returned \" . count($servers) . \" server(s)\");\n return $servers;\n }\n\n public static function getDeepSeekApiKey(): string\n {\n $key = trim(self::get('DEEPSEEK_API_KEY'));\n \n if (empty($key)) {\n error_log('[Config] ERROR: DEEPSEEK_API_KEY is empty or not set in .env file');\n error_log('[Config] .env file path: ' . (self::$envFile ?? 'not initialized'));\n throw new RuntimeException('DEEPSEEK_API_KEY is not configured. Please set it in .env file');\n }\n \n // Проверка формата (должен начинаться с sk-)\n if (!str_starts_with($key, 'sk-')) {\n error_log('[Config] WARNING: DEEPSEEK_API_KEY does not start with \"sk-\"');\n }\n \n // Логируем только префикс для отладки (безопасно)\n error_log('[Config] DEEPSEEK_API_KEY loaded: ' . substr($key, 0, 7) . '... (length: ' . strlen($key) . ')');\n \n return $key;\n }\n\n public static function getDeepSeekBaseUrl(): string\n {\n return self::get('DEEPSEEK_BASE_URL', 'https://api.deepseek.com/v1');\n }\n\n public static function getDeepSeekModel(): string\n {\n return self::get('DEEPSEEK_MODEL', 'deepseek-chat');\n }\n\n public static function getDeepSeekTimeout(): int\n {\n return self::getInt('DEEPSEEK_TIMEOUT', 30);\n }\n\n public static function getMcpTimeout(): int\n {\n return self::getInt('MCP_TIMEOUT', 60);\n }\n\n public static function getContextMaxMessages(): int\n {\n return self::getInt('CONTEXT_MAX_MESSAGES', 20);\n }\n\n public static function getContextBaseDir(): string\n {\n return self::get('CONTEXT_BASE_DIR', 'src/context');\n }\n}\n\n"}, "2af701f88c5bbad88f5d8d84c820ea180e530a78": {"t": 1785756422.3319068, "n": 5364, "h": "82f54577d0ce95c4", "c": "<?php\n\ndeclare(strict_types=1);\n\nclass Config\n{\n private static ?array $cache = null;\n private static string $envFile;\n\n public static function init(string $envFile = null): void\n {\n if ($envFile === null) {\n // Попытка найти .env в разных местах\n $possiblePaths = [\n __DIR__ . '/../../.env', // Относительно src/classes/config/\n '/var/www/html/.env', // В Docker контейнере\n __DIR__ . '/../../../.env', // Альтернативный путь\n ];\n \n foreach ($possiblePaths as $path) {\n if (file_exists($path)) {\n $envFile = $path;\n break;\n }\n }\n \n if ($envFile === null) {\n $envFile = __DIR__ . '/../../.env'; // По умолчанию\n }\n }\n self::$envFile = $envFile;\n self::loadEnv();\n }\n\n private static function loadEnv(): void\n {\n if (self::$cache !== null) {\n return;\n }\n\n self::$cache = [];\n\n if (!file_exists(self::$envFile)) {\n error_log(\"[Config] .env file not found: \" . self::$envFile);\n return;\n }\n\n $lines = file(self::$envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);\n foreach ($lines as $line) {\n $line = trim($line);\n if (str_starts_with($line, '#')) {\n continue;\n }\n\n $parts = explode('=', $line, 2);\n if (count($parts) === 2) {\n $key = trim($parts[0]);\n $value = trim($parts[1]);\n // Удаляем кавычки, если они есть\n if ((str_starts_with($value, '\"') && str_ends_with($value, '\"')) ||\n (str_starts_with($value, \"'\") && str_ends_with($value, \"'\"))) {\n $value = substr($value, 1, -1);\n }\n self::$cache[$key] = $value;\n }\n }\n }\n\n public static function get(string $key, string $default = ''): string\n {\n if (self::$cache === null) {\n self::init();\n }\n\n return self::$cache[$key] ?? getenv($key) ?: $default;\n }\n\n public static function getInt(string $key, int $default = 0): int\n {\n $value = self::get($key, (string)$default);\n return (int)$value;\n }\n\n public static function getArray(string $key, string $separator = ','): array\n {\n $value = self::get($key, '');\n error_log(\"[Config] getArray('{$key}') raw value: '\" . addslashes($value) . \"' (length: \" . strlen($value) . \")\");\n \n if (empty($value)) {\n error_log(\"[Config] getArray('{$key}') returned empty array\");\n return [];\n }\n \n $result = array_map('trim', explode($separator, $value));\n $result = array_filter($result, function($item) {\n return !empty($item);\n });\n \n // Дополнительная очистка: удаляем запятые в начале/конце каждого элемента\n $result = array_map(function($item) {\n return trim($item, \" \\t\\n\\r\\0\\x0B,\");\n }, $result);\n $result = array_filter($result, function($item) {\n return !empty($item);\n });\n \n error_log(\"[Config] getArray('{$key}') parsed to \" . count($result) . \" items: \" . json_encode($result, JSON_UNESCAPED_UNICODE));\n return array_values($result);\n }\n\n public static function getMcpServers(): array\n {\n $servers = self::getArray('MCP_SERVERS');\n error_log(\"[Config] getMcpServers() returned \" . count($servers) . \" server(s)\");\n return $servers;\n }\n\n public static function getDeepSeekApiKey(): string\n {\n $key = trim(self::get('DEEPSEEK_API_KEY'));\n \n if (empty($key)) {\n error_log('[Config] ERROR: DEEPSEEK_API_KEY is empty or not set in .env file');\n error_log('[Config] .env file path: ' . (self::$envFile ?? 'not initialized'));\n throw new RuntimeException('DEEPSEEK_API_KEY is not configured. Please set it in .env file');\n }\n \n // Проверка формата (должен начинаться с sk-)\n if (!str_starts_with($key, 'sk-')) {\n error_log('[Config] WARNING: DEEPSEEK_API_KEY does not start with \"sk-\"');\n }\n \n // Логируем только префикс для отладки (безопасно)\n error_log('[Config] DEEPSEEK_API_KEY loaded: ' . substr($key, 0, 7) . '... (length: ' . strlen($key) . ')');\n \n return $key;\n }\n\n public static function getDeepSeekBaseUrl(): string\n {\n return self::get('DEEPSEEK_BASE_URL', 'https://api.deepseek.com/v1');\n }\n\n public static function getDeepSeekModel(): string\n {\n return self::get('DEEPSEEK_MODEL', 'deepseek-chat');\n }\n\n public static function getDeepSeekTimeout(): int\n {\n return self::getInt('DEEPSEEK_TIMEOUT', 30);\n }\n\n public static function getMcpTimeout(): int\n {\n return self::getInt('MCP_TIMEOUT', 60);\n }\n\n public static function getContextMaxMessages(): int\n {\n return self::getInt('CONTEXT_MAX_MESSAGES', 20);\n }\n\n public static function getContextBaseDir(): string\n {\n return self::get('CONTEXT_BASE_DIR', 'src/context');\n }\n}\n\n"}}}}