fix(nginx-log): service 文件加 Service 后缀(命名规范合规)

F2 Code quality review 发现:3 个新增 service 未遵守
.agents/rules/ulthon-naming-convention.md 第 19 行规定
(service 模块文件名需带 Service 后缀)。

变更:
- 重命名 6 个文件(3 Base + 3 App):
  NginxLogParser(Base)→NginxLogParserService(Base)
  NginxLogReader(Base)→NginxLogReaderService(Base)
  NginxLogAggregator(Base)→NginxLogAggregatorService(Base)
- 同步类名、use、类型 hint、new 引用
- NginxLogReaderServiceBase 异常消息前缀同步加 Service
- controller Base 引用更新(NginxLogImportBase / NginxLogStatAggregateBase)

验证:
- php -l 全部 8 个文件语法通过
- grep 残留旧名 = 0 结果(24 处引用全部带 Service 后缀)
This commit is contained in:
augushong
2026-07-28 06:57:13 +08:00
parent 0f9f12174c
commit f1a2e8fd5d
10 changed files with 49 additions and 49 deletions

View File

@@ -19,7 +19,7 @@ use think\facade\Db;
* - 依赖倒置:内部 use app 入口 modelNginxStatHour 等),不 use Base model
* - 只读 raw ul_nginx_access_log不做 nginx log line 解析(那是 T5 Parser 的事)
*/
class NginxLogAggregatorBase
class NginxLogAggregatorServiceBase
{
/**
* 聚合指定日期的指定小时.

View File

@@ -13,9 +13,9 @@ use DateTime;
* 示例行:
* 192.168.32.1 - - [27/Jul/2026:16:20:15 +0000] "GET / HTTP/1.1" 499 0 "-" "Mozilla/5.0 (...)" 5.085 5.086 0
*
* 业务侧通过 app/common/service/NginxLogParser 覆盖本类方法.
* 业务侧通过 app/common/service/NginxLogParserService 覆盖本类方法.
*/
class NginxLogParserBase
class NginxLogParserServiceBase
{
/** 爬虫 UA 关键词(大小写不敏感匹配) */
public const SPIDER_KEYWORDS = [

View File

@@ -17,7 +17,7 @@ use app\admin\model\NginxLogPosition;
* 依赖倒置:内部 model 调用走 `app\admin\model\NginxLogPosition`App 入口类),
* 使用者可在 app/ 重写该 model 拦截行为;本类不直接 `new NginxLogPosition`(静态调用满足多态)。
*/
class NginxLogReaderBase
class NginxLogReaderServiceBase
{
/** 单次 fread 的 buffer 大小64KB */
protected const BUFFER_SIZE = 65536;
@@ -49,7 +49,7 @@ class NginxLogReaderBase
{
$fp = @fopen($filePath, 'rb');
if ($fp === false) {
throw new \RuntimeException("NginxLogReader: 无法打开文件 {$filePath}");
throw new \RuntimeException("NginxLogReaderService: 无法打开文件 {$filePath}");
}
try {
@@ -57,7 +57,7 @@ class NginxLogReaderBase
clearstatcache(true, $filePath);
$stat = fstat($fp);
if ($stat === false) {
throw new \RuntimeException("NginxLogReader: fstat 失败 {$filePath}");
throw new \RuntimeException("NginxLogReaderService: fstat 失败 {$filePath}");
}
$currentInode = (int) $stat['ino'];
$currentSize = (int) $stat['size'];
@@ -81,7 +81,7 @@ class NginxLogReaderBase
// 步骤 4fseek 到 offset
if ($offset > 0 && fseek($fp, $offset) !== 0) {
throw new \RuntimeException("NginxLogReader: fseek 失败 offset={$offset} file={$filePath}");
throw new \RuntimeException("NginxLogReaderService: fseek 失败 offset={$offset} file={$filePath}");
}
$yielded = 0;
@@ -95,7 +95,7 @@ class NginxLogReaderBase
$chunk = fread($fp, self::BUFFER_SIZE);
if ($chunk === false) {
// 读错误:交上层处理,不保存进度(下次重读)
throw new \RuntimeException("NginxLogReader: fread 失败 file={$filePath}");
throw new \RuntimeException("NginxLogReaderService: fread 失败 file={$filePath}");
}
if ($chunk === '') {
// EOF

View File

@@ -67,8 +67,8 @@ class NginxLogImportBase extends TimerController
}
// 3. 依赖倒置:使用 app 层入口类(业务侧可重写拦截)
$parser = new \app\common\service\NginxLogParser();
$reader = new \app\common\service\NginxLogReader();
$parser = new \app\common\service\NginxLogParserService();
$reader = new \app\common\service\NginxLogReaderService();
// 静态资源过滤开关
$excludeStatic = (int) sysconfig('nginx_log', 'exclude_static', 1) === 1;
@@ -119,8 +119,8 @@ class NginxLogImportBase extends TimerController
* @return array{lines:int,fails:int}
*/
protected function processFile(
\app\common\service\NginxLogParser $parser,
\app\common\service\NginxLogReader $reader,
\app\common\service\NginxLogParserService $parser,
\app\common\service\NginxLogReaderService $reader,
string $file,
bool $excludeStatic
): array {
@@ -233,7 +233,7 @@ class NginxLogImportBase extends TimerController
* 这里取当前 position 后用相同 offset 重写,仅更新 failCount / failSamples。
*/
protected function updateFailStats(
\app\common\service\NginxLogReader $reader,
\app\common\service\NginxLogReaderService $reader,
string $file,
int $fails,
array $samples

View File

@@ -14,7 +14,7 @@ use think\facade\Log;
* 1. env 总开关校验(严格布尔判断,详见 notepad Task 2 #14
* 2. 计算目标统计窗口:默认 now - 1 hour上一完整小时
* 支持 ?date=YYYYMMDD&hour=HH 手动指定(用于补跑历史数据)
* 3. 依赖倒置:实例化 app 层 NginxLogAggregator调 aggregateHour($date, $hour)
* 3. 依赖倒置:实例化 app 层 NginxLogAggregatorService,调 aggregateHour($date, $hour)
* 4. return JSON含 stat_hour_rows / stat_url_rows / stat_referer_rows / stat_ua_rows
*
* 业务侧如需定制聚合触发逻辑(如改默认窗口策略、加业务过滤),重写
@@ -69,7 +69,7 @@ class NginxLogStatAggregateBase extends TimerController
}
// 3. 依赖倒置:调用 app 层入口类(业务侧可重写拦截)
$aggregator = new \app\common\service\NginxLogAggregator();
$aggregator = new \app\common\service\NginxLogAggregatorService();
$result = $aggregator->aggregateHour($dateInt, $hourInt);
// 4. return JSON补充窗口信息便于日志检索