Update PHP version to 8.4 and add property hooks

This commit is contained in:
Ruben 2025-11-01 23:33:09 +01:00
parent 32449d2edd
commit 673c02d237
14 changed files with 939 additions and 606 deletions

View file

@ -14,12 +14,8 @@ function getSubdirectories(string $dir): array {
);
}
function getLangPrefix(string $currentLang, string $defaultLang): string {
return $currentLang !== $defaultLang ? "/$currentLang" : '';
}
function extractTitle(string $filePath, string $lang, string $defaultLang): ?string {
$files = findAllContentFiles($filePath, $lang, $defaultLang);
$files = findAllContentFiles($filePath, $lang, $defaultLang, []);
if (empty($files)) return null;
// Check the first content file for a title
@ -55,15 +51,16 @@ function extractDateFromFolder(string $folderName): ?string {
}
function findCoverImage(string $dirPath): ?string {
foreach (COVER_IMAGE_EXTENSIONS as $ext) {
if (file_exists("$dirPath/cover.$ext")) {
return "cover.$ext";
}
}
return null;
// PHP 8.4: array_find() - cleaner than foreach
$found = array_find(
COVER_IMAGE_EXTENSIONS,
fn($ext) => file_exists("$dirPath/cover.$ext")
);
return $found ? "cover.$found" : null;
}
function findPdfFile(string $dirPath): ?string {
$pdfs = glob("$dirPath/*.pdf");
// PHP 8.4: array_find() with glob
$pdfs = glob("$dirPath/*.pdf") ?: [];
return $pdfs ? basename($pdfs[0]) : null;
}