init
This commit is contained in:
@@ -63,6 +63,32 @@ class Config
|
||||
get => $this->tcpServerPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* 摄像头配置列表
|
||||
*/
|
||||
public array $cameraConfig {
|
||||
get => $this->cameraConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* ZLM配置
|
||||
*/
|
||||
public ZLMConfig $zlm {
|
||||
get => $this->zlm;
|
||||
}
|
||||
public string $httpIP{
|
||||
get => $this->httpIP;
|
||||
}
|
||||
public int $httpPort{
|
||||
get => $this->httpPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* 人员检测回调函数
|
||||
* @var callable|null
|
||||
*/
|
||||
private $personDetectionCallback = null;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
$this->database = new DatabaseConfig();
|
||||
@@ -79,12 +105,56 @@ class Config
|
||||
default => \Monolog\Logger::DEBUG
|
||||
};
|
||||
$this->tcpServerPort = self::getIntEnv('TCP_SERVER_PORT', 50000);
|
||||
$this->logRotationTimeByDay = self::getIntEnv('LOG_ROTATION_TIME_BY_DAY', 14);
|
||||
$this->errorLogRotationTimeByDay = self::getIntEnv('ERROR_LOG_ROTATION_TIME_BY_DAY', 30);
|
||||
$this->cameraConfig = $this->loadCameraConfig();
|
||||
$this->httpIP = self::getStringEnv('HTTP_IP', '0.0.0.0');
|
||||
$this->httpPort = self::getIntEnv('HTTP_PORT', 8080);
|
||||
$this->zlm = new ZLMConfig();
|
||||
$this->personDetectionCallback = null;
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && $this->tcpServerProcessNum > 1) {
|
||||
$this->tcpServerProcessNum = 1;
|
||||
echo "Warning: TCP_SERVER_PROCESS_NUM set to 1 on Windows.\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载摄像头配置
|
||||
*/
|
||||
private function loadCameraConfig(): array
|
||||
{
|
||||
// 从环境变量加载摄像头配置
|
||||
// 格式: CAMERA_CONFIG={"camera_01":{"rtsp_url":"rtsp://...","enabled":true}}
|
||||
$configJson = self::getStringEnv('CAMERA_CONFIG', '');
|
||||
if (!empty($configJson)) {
|
||||
$config = json_decode($configJson, true);
|
||||
if (is_array($config)) {
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
|
||||
// 默认空配置
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取人员检测回调函数
|
||||
* @return callable|null
|
||||
*/
|
||||
public function getPersonDetectionCallback(): ?callable
|
||||
{
|
||||
return $this->personDetectionCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置人员检测回调函数
|
||||
* @param callable|null $callback
|
||||
*/
|
||||
public function setPersonDetectionCallback(?callable $callback): void
|
||||
{
|
||||
$this->personDetectionCallback = $callback;
|
||||
}
|
||||
|
||||
private function __clone()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace app\config;
|
||||
|
||||
/**
|
||||
* ZLMediaKit 配置类
|
||||
*/
|
||||
class ZLMConfig
|
||||
{
|
||||
/**
|
||||
* ZLM服务器主机地址
|
||||
*/
|
||||
public string $host {
|
||||
get => $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* ZLM服务器端口
|
||||
*/
|
||||
public int $port {
|
||||
get => $this->port;
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求协议 (http/https)
|
||||
*/
|
||||
public string $schema {
|
||||
get => $this->schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* ZLM API密钥
|
||||
*/
|
||||
public string $secret {
|
||||
get => $this->secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 完整地址 host:port
|
||||
*/
|
||||
public string $address {
|
||||
get => "{$this->host}:{$this->port}";
|
||||
}
|
||||
|
||||
/**
|
||||
* API基础URL
|
||||
*/
|
||||
public string $apiBaseUrl {
|
||||
get => "{$this->schema}://{$this->host}:{$this->port}";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->host = Config::getStringEnv('ZLM_HOST', '127.0.0.1');
|
||||
$this->port = Config::getIntEnv('ZLM_PORT', 80);
|
||||
$this->schema = Config::getStringEnv('ZLM_SCHEMA', 'http');
|
||||
$this->secret = Config::getStringEnv('ZLM_SECRET', '');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user