refactor: 拆分 config.php 为 lib/ 模块,消除页面层重复代码
纯结构性重构,不改变任何功能。 - config.php 由 739 行缩减为 42 行,改为纯引导入口;新增 ROOT_DIR 常量 统一拼接绝对路径(lib/ 内模块的 __DIR__ 会指向 lib/,必须替换) - 新增 lib/ 五个模块 db.php / helpers.php / auth.php / movies.php / stats.php, 由 config.php 按 db → helpers → auth → movies → stats 顺序加载 - add.php、edit.php 各自约 80 行重复的 POST 处理改为调用 resolveCinemaId / resolvePersonIds / linkViewers / uploadImageFile / saveBase64Image / uploadMultiplePhotos / deleteStoredFile - cinemas.php、persons.php 中重复 4 次的颜色校验改用 normalizeHexColor() - toggleNewViewer / removeViewerRow / toggleNewCinema 下沉至 js/main.js, add.php 中的 removeViewer 统一更名为 removeViewerRow - 删除死代码:imageUrl()(全项目无调用);cinemas.php 配色数组中本就会被 array_slice 丢弃的 extra 颜色逻辑,简化为单条扁平 50 元素数组 - README 目录结构补充 lib/ 说明 验证方式:以便携 PHP 8.4 搭建 A/B 回归环境,播种固定数据后遍历 47 个 GET/POST 端点录制「状态码 + 响应体」。重构前后 42 个逐字节相同、2 个仅 上传文件名时间戳不同、3 个差异均为内联脚本下沉(已单独校验函数体逐字符 等价,剥离脚本后 HTML 标记完全一致)。24 个 PHP 文件语法检查全部通过。
This commit is contained in:
+2
-6
@@ -18,9 +18,7 @@ $movie = $stmt->fetch();
|
||||
if ($movie) {
|
||||
// 删除海报、票根、旧单张照片
|
||||
foreach (['poster_path', 'ticket_path', 'photo_path'] as $field) {
|
||||
if (!empty($movie[$field]) && file_exists(__DIR__ . '/' . $movie[$field])) {
|
||||
unlink(__DIR__ . '/' . $movie[$field]);
|
||||
}
|
||||
deleteStoredFile($movie[$field]);
|
||||
}
|
||||
|
||||
// 删除多张照片(新表)
|
||||
@@ -28,9 +26,7 @@ if ($movie) {
|
||||
$stmt2->execute([$id]);
|
||||
$photos = $stmt2->fetchAll();
|
||||
foreach ($photos as $p) {
|
||||
if (!empty($p['photo_path']) && file_exists(__DIR__ . '/' . $p['photo_path'])) {
|
||||
unlink(__DIR__ . '/' . $p['photo_path']);
|
||||
}
|
||||
deleteStoredFile($p['photo_path']);
|
||||
}
|
||||
|
||||
// 删除电影(viewers 和 movie_photos 会自动级联删除)
|
||||
|
||||
Reference in New Issue
Block a user