Skip to content

Commit 597d47b

Browse files
committed
Update releases/branches.php API to use VersionData
1 parent 95e13fc commit 597d47b

1 file changed

Lines changed: 12 additions & 20 deletions

File tree

releases/branches.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
<?php
22

3-
include_once __DIR__ . '/../include/prepend.inc';
4-
include_once __DIR__ . '/../include/branches.inc';
5-
6-
header('Content-Type: application/json; charset=UTF-8');
3+
use phpweb\Releases\VersionData;
74

8-
function formatDate($date = null) {
9-
return $date !== null ? $date->format('c') : null;
10-
}
5+
include_once __DIR__ . '/../include/prepend.inc';
116

127
$current = [];
13-
foreach (get_all_branches() as $major => $releases) {
14-
foreach ($releases as $branch => $release) {
15-
$current[$branch] = [
16-
'branch' => $branch,
17-
'latest' => ($release['version'] ?? null),
18-
'state' => get_branch_support_state($branch),
19-
'initial_release' => formatDate(get_branch_release_date($branch)),
20-
'active_support_end' => formatDate(get_branch_bug_eol_date($branch)),
21-
'security_support_end' => formatDate(get_branch_security_eol_date($branch)),
22-
];
23-
}
8+
foreach (VersionData::sort(VersionData::all(), 'desc') as $release) {
9+
$current[] = [
10+
'branch' => $release->label,
11+
'latest' => $release->latestRelease?->label,
12+
'state' => $release->supportState->value,
13+
'initial_release' => $release->releaseDate?->format('c'),
14+
'active_support_end' => $release->bugfixEOL?->format('c'),
15+
'security_support_end' => $release->securityEOL?->format('c'),
16+
];
2417
}
2518

26-
// Sorting should already be correct based on return of get_all_branches(),
27-
// but enforce it here anyway, just to be nice.
2819
usort($current, fn($a, $b) => version_compare($b['branch'], $a['branch']));
2920

21+
header('Content-Type: application/json; charset=UTF-8');
3022
echo json_encode($current);

0 commit comments

Comments
 (0)