From c79ce4568ccb3483492a57743588e2fdd66ea377 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Sat, 2 Nov 2024 16:36:35 +0100 Subject: [PATCH] Changelog : corrections pour le vieux PHP de Free, plus quelques oublis --- communs/changelog.inc.php | 107 +++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 58 deletions(-) diff --git a/communs/changelog.inc.php b/communs/changelog.inc.php index 19dab58..5a40302 100644 --- a/communs/changelog.inc.php +++ b/communs/changelog.inc.php @@ -8,6 +8,9 @@ class GepapirChangelog { public static function getChangelogEntries() { return [ + new ChangelogEntry('2024-11-02', '8.3.1', [ + 'Changelog : corrections pour le vieux PHP de Free, plus quelques oublis', + ]), new ChangelogEntry('2024-11-02', '8.3.0', [ 'Changelog : passage en dynamique', "Changelog : rss généré maison pour remplacer le service Feed43 qui n'existe plus", @@ -222,49 +225,13 @@ public static function getChangelogEntries() ]; } - public static function getCurrentVersion():string { + /** + * @return string + */ + public static function getCurrentVersion() { $latestEntry = static::getChangelogEntries()[0]; - return $latestEntry->entryVersion; - } - - public static function getForHtml($numberOfEntriesToReturn = 10):string { - $htmlChangelog = '
'; - $changelogEntries = static::getChangelogEntries(); - $numberOfEntriesReturned = 0; - - foreach ($changelogEntries as $changelogEntry) { - if ($numberOfEntriesReturned >= $numberOfEntriesToReturn) { - break; - } - - $entryDate = $changelogEntry->entryDate; - $entryVersion = $changelogEntry->entryVersion; - $entryTitle = $entryDate; - if (!is_null($entryVersion)) { - $entryTitle .= ', v' . $entryVersion; - } - - $htmlChangelog .= <<{$entryTitle} -
-HTML; - - $entryContent = $changelogEntry->aEntryContent; - foreach ($entryContent as $entryContentItem) { - $htmlChangelog .= '- ' . $entryContentItem.'
'; - } - - $htmlChangelog .= '
'; - $numberOfEntriesReturned++; - } - - $htmlChangelog .= '
'; - - return $htmlChangelog; - } - - public static function getForRss():string { - return 'TODO'; + $currentVersion = $latestEntry->entryVersion; + return (is_null($currentVersion)) ? 'N/A' : $currentVersion; } } @@ -293,7 +260,11 @@ function __construct(string $entryDate, ?string $entryVersion, array $aEntryCont * @uses GepapirChangelog */ abstract class AbstractChangelogRenderer { - public static function getContent($numberOfEntriesToReturn = null): string + /** + * @param ?int $numberOfEntriesToReturn + * @return string + */ + public static function getContent($numberOfEntriesToReturn = null) { $htmlChangelog = static::getHeader(); $changelogEntries = GepapirChangelog::getChangelogEntries(); @@ -327,37 +298,56 @@ public static function getContent($numberOfEntriesToReturn = null): string return $htmlChangelog; } - abstract protected static function getHeader(): string; - abstract protected static function getEntryBefore(string $entryTitle, string $entryId): string; - abstract protected static function getEntryContentItem(string $entryContentItem): string; - abstract protected static function getEntryAfter(): string; - abstract protected static function getFooter(): string; + /** + * @return string + */ + abstract protected static function getHeader(); + /** + * @param string $entryTitle + * @param string $entryId + * @return string + */ + abstract protected static function getEntryBefore(string $entryTitle, string $entryId); + /** + * @param string $entryContentItem + * @return string + */ + abstract protected static function getEntryContentItem(string $entryContentItem); + /** + * @return string + */ + abstract protected static function getEntryAfter(); + /** + * @return string + */ + abstract protected static function getFooter(); } class HtmlChangelogRenderer extends AbstractChangelogRenderer { - protected static function getHeader(): string + protected static function getHeader() { return '
'; } - protected static function getEntryBefore(string $entryTitle, string $entryId):string { + protected static function getEntryBefore(string $entryTitle, string $entryId) { return <<{$entryTitle}
HTML; } - protected static function getEntryContentItem(string $entryContentItem): string { + + protected static function getEntryContentItem(string $entryContentItem) { return '- ' . $entryContentItem . '
'; } - protected static function getEntryAfter(): string + protected static function getEntryAfter() { return '
'; } - protected static function getFooter(): string + protected static function getFooter() { return '
'; } @@ -372,7 +362,8 @@ protected static function getFooter(): string */ class RssChangelogRenderer extends AbstractChangelogRenderer { - protected static function getHeader():string { + protected static function getHeader() + { return << @@ -384,7 +375,7 @@ protected static function getHeader():string { XML; } - protected static function getEntryBefore(string $entryTitle, string $entryId): string + protected static function getEntryBefore(string $entryTitle, string $entryId) { $entryTitleEscaped = htmlspecialchars($entryTitle); return << @@ -409,7 +400,7 @@ protected static function getEntryAfter(): string XML; } - protected static function getFooter(): string + protected static function getFooter() { return <<