Skip to content

Commit d353cf2

Browse files
Mark Randallderickr
authored andcommitted
Add more reliable way of accessing branch / version / release data without having to rely on global-scoped variables.
1 parent 18956bb commit d353cf2

21 files changed

Lines changed: 869 additions & 207 deletions

bin/bumpRelease

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
#!/usr/bin/env php
22
<?php
3+
4+
use phpweb\Releases\Branches;
5+
36
(PHP_SAPI === 'cli') or die("Please run this script using the cli sapi");
47

5-
require_once __DIR__ . "/../include/branches.inc";
6-
require_once __DIR__ . "/../include/version.inc";
7-
require_once __DIR__ . "/../include/releases.inc";
8+
require __DIR__ . '/../include/releases.inc';
9+
require __DIR__ . '/../src/autoload.php';
810

911
if ($_SERVER['argc'] < 1) {
1012
fwrite(STDERR, "Usage: {$_SERVER['argv'][0]} major_version [ minor_version ]\n");
1113
exit(1);
1214
}
1315

16+
$RELEASES = Branches::getReleaseData();
1417
$major = (int) $_SERVER['argv'][1];
1518
isset($RELEASES[$major]) or die("Unknown major version $major");
1619
$minor = isset($_SERVER['argv'][2]) ? (int) $_SERVER['argv'][2] : null;
1720

18-
$version = get_current_release_for_branch($major, $minor);
21+
$version = Branches::getCurrentReleaseForBranch($major, $minor);
1922
$info = $RELEASES[$major][$version] ?? null;
2023

2124
if ($info === null) {
@@ -34,7 +37,7 @@ $OLDRELEASES[$major] = array_merge(
3437
);
3538

3639
file_put_contents(__DIR__ . "/../include/releases.inc", [
37-
"<?php\n\$OLDRELEASES = ",
40+
"<?php\nreturn \$OLDRELEASES = ",
3841
var_export($OLDRELEASES, true),
3942
";\n",
4043
]);

include/branch-overrides.inc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
return [
4+
/* 3.0 is here because version_compare() can't handle the only version in
5+
* $OLDRELEASES, and it saves another special case in
6+
* Branches::getBranchSecurityEOLDate(). */
7+
'3.0' => [
8+
'security' => '2000-10-20',
9+
],
10+
'5.3' => [
11+
'stable' => '2013-07-11',
12+
'security' => '2014-08-14',
13+
],
14+
'5.4' => [
15+
'stable' => '2014-09-14',
16+
'security' => '2015-09-03',
17+
],
18+
'5.5' => [
19+
'stable' => '2015-07-10',
20+
'security' => '2016-07-21',
21+
],
22+
'5.6' => [
23+
'stable' => '2017-01-19',
24+
'security' => '2018-12-31',
25+
],
26+
'7.0' => [
27+
'stable' => '2018-01-04',
28+
'security' => '2019-01-10',
29+
],
30+
'8.4' => [
31+
'date' => '2024-11-21',
32+
],
33+
];

include/branches.inc

Lines changed: 92 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use phpweb\Releases\Branches;
4+
35
include_once __DIR__ . '/releases.inc';
46
include_once __DIR__ . '/version.inc';
57

@@ -10,37 +12,7 @@ include_once __DIR__ . '/version.inc';
1012
* - stable: the end of active support (usually two years after release).
1113
* - security: the end of security support (usually release + 3 years).
1214
*/
13-
$BRANCHES = [
14-
/* 3.0 is here because version_compare() can't handle the only version in
15-
* $OLDRELEASES, and it saves another special case in
16-
* get_branch_security_eol_date(). */
17-
'3.0' => [
18-
'security' => '2000-10-20',
19-
],
20-
'5.3' => [
21-
'stable' => '2013-07-11',
22-
'security' => '2014-08-14',
23-
],
24-
'5.4' => [
25-
'stable' => '2014-09-14',
26-
'security' => '2015-09-03',
27-
],
28-
'5.5' => [
29-
'stable' => '2015-07-10',
30-
'security' => '2016-07-21',
31-
],
32-
'5.6' => [
33-
'stable' => '2017-01-19',
34-
'security' => '2018-12-31',
35-
],
36-
'7.0' => [
37-
'stable' => '2018-01-04',
38-
'security' => '2019-01-10',
39-
],
40-
'8.4' => [
41-
'date' => '2024-11-21',
42-
],
43-
];
15+
$BRANCHES = require __DIR__ . '/branch-overrides.inc';
4416

4517
/* Time to keep EOLed branches in the array returned by get_active_branches(),
4618
* which is used on the front page download links and the supported versions
@@ -98,6 +70,7 @@ function version_number_to_branch(string $version): ?string {
9870
return null;
9971
}
10072

73+
#[Deprecated('Use Branches::get_all_branches()')]
10174
function get_all_branches() {
10275
$branches = [];
10376

@@ -135,7 +108,8 @@ function get_all_branches() {
135108
return $branches;
136109
}
137110

138-
function get_active_branches($include_recent_eols = true) {
111+
#[Deprecated('Use Branches::active()')]
112+
function get_active_branches(bool $include_recent_eols = true) {
139113
$branches = [];
140114
$now = new DateTime();
141115

@@ -170,6 +144,7 @@ function get_active_branches($include_recent_eols = true) {
170144
/* If you provide an array to $always_include, note that the version numbers
171145
* must be in $RELEASES _and_ must be the full version number, not the branch:
172146
* ie provide array('5.3.29'), not array('5.3'). */
147+
#[Deprecated('Use Branches::eol()')]
173148
function get_eol_branches($always_include = null) {
174149
$always_include = $always_include ?: [];
175150
$branches = [];
@@ -246,6 +221,7 @@ function get_eol_branches($always_include = null) {
246221
* MAJOR.MINOR.REVISION (the REVISION will be ignored if provided). This will
247222
* return either null (if no release exists on the given branch), or the usual
248223
* version metadata from $RELEASES for a single release. */
224+
#[Deprecated('Use Branches::getInitialRelease')]
249225
function get_initial_release($branch) {
250226
$branch = version_number_to_branch($branch);
251227
if (!$branch) {
@@ -274,6 +250,7 @@ function get_initial_release($branch) {
274250
return null;
275251
}
276252

253+
#[Deprecated('Use Branches::getFinalRelease')]
277254
function get_final_release($branch) {
278255
$branch = version_number_to_branch($branch);
279256
if (!$branch) {
@@ -305,6 +282,7 @@ function get_final_release($branch) {
305282
return null;
306283
}
307284

285+
#[Deprecated('Use Branches::getBranchBugsEOLDate')]
308286
function get_branch_bug_eol_date($branch): ?DateTime
309287
{
310288
if (isset($GLOBALS['BRANCHES'][$branch]['stable'])) {
@@ -324,6 +302,7 @@ function get_branch_bug_eol_date($branch): ?DateTime
324302
return $date?->setDate($date->format('Y'), 12, 31);
325303
}
326304

305+
#[Deprecated('Use Branches::getBranchSecurityEOLDate')]
327306
function get_branch_security_eol_date($branch): ?DateTime
328307
{
329308
if (isset($GLOBALS['BRANCHES'][$branch]['security'])) {
@@ -351,13 +330,15 @@ function get_branch_security_eol_date($branch): ?DateTime
351330
return $date?->setDate($date->format('Y'), 12, 31);
352331
}
353332

333+
#[Deprecated('Use Branches::getBranchReleaseDate')]
354334
function get_branch_release_date($branch): ?DateTime
355335
{
356336
$initial = get_initial_release($branch);
357337

358338
return isset($initial['date']) ? new DateTime($initial['date']) : null;
359339
}
360340

341+
#[Deprecated('Use Branches::getBranchSupportState')]
361342
function get_branch_support_state($branch) {
362343
$initial = get_branch_release_date($branch);
363344
$bug = get_branch_bug_eol_date($branch);
@@ -399,7 +380,7 @@ function compare_version(array $arrayA, string $versionB)
399380
return 0;
400381
}
401382

402-
function version_array(string $version, ?int $length = null)
383+
function version_array(string $version, ?int $length = null): mixed
403384
{
404385
$versionArray = array_map(
405386
'intval',
@@ -419,6 +400,7 @@ function version_array(string $version, ?int $length = null)
419400
return $versionArray;
420401
}
421402

403+
#[Deprecated('Use Branches::getCurrentReleaseForBranch')]
422404
function get_current_release_for_branch(int $major, ?int $minor): ?string {
423405
global $RELEASES, $OLDRELEASES;
424406

@@ -441,3 +423,80 @@ function get_current_release_for_branch(int $major, ?int $minor): ?string {
441423

442424
return null;
443425
}
426+
427+
428+
// Get latest release version and info.
429+
/**
430+
* @return array{mixed,mixed}
431+
*/
432+
function release_get_latest(): array {
433+
$RELEASES = Branches::getReleaseData();
434+
435+
$version = '0.0.0';
436+
$current = null;
437+
foreach ($RELEASES as $versions) {
438+
foreach ($versions as $ver => $info) {
439+
if (version_compare($ver, $version) > 0) {
440+
$version = $ver;
441+
$current = $info;
442+
}
443+
}
444+
}
445+
446+
return [$version, $current];
447+
}
448+
449+
function show_source_releases(): void
450+
{
451+
$RELEASES = Branches::getReleaseData();
452+
453+
$SHOW_COUNT = 4;
454+
455+
$current_uri = htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8');
456+
457+
$i = 0; foreach ($RELEASES as $MAJOR => $major_releases): /* major releases loop start */
458+
$releases = array_slice($major_releases, 0, $SHOW_COUNT);
459+
?>
460+
<a id="v<?php echo $MAJOR; ?>"></a>
461+
<?php foreach ($releases as $v => $a): ?>
462+
<?php $mver = substr($v, 0, strrpos($v, '.')); ?>
463+
<?php $stable = $i++ === 0 ? "Current Stable" : "Old Stable"; ?>
464+
465+
<h3 id="v<?php echo $v; ?>" class="title">
466+
<span class="release-state"><?php echo $stable; ?></span>
467+
PHP <?php echo $v; ?>
468+
(<a href="/ChangeLog-<?php echo $MAJOR; ?>.php#<?php echo urlencode($v); ?>" class="changelog">Changelog</a>)
469+
</h3>
470+
<div class="content-box">
471+
472+
<ul>
473+
<?php foreach ($a['source'] as $rel): ?>
474+
<li>
475+
<?php download_link($rel['filename'], $rel['filename']); ?>
476+
<span class="releasedate"><?php echo date('d M Y', strtotime($rel['date'])); ?></span>
477+
<?php
478+
if (isset($rel['md5'])) echo '<span class="md5sum">', $rel['md5'], '</span>';
479+
if (isset($rel['sha256'])) echo '<span class="sha256">', $rel['sha256'], '</span>';
480+
?>
481+
<?php if (isset($rel['note']) && $rel['note']): ?>
482+
<p>
483+
<strong>Note:</strong>
484+
<?php echo $rel['note']; ?>
485+
</p>
486+
<?php endif; ?>
487+
</li>
488+
<?php endforeach; ?>
489+
<li>
490+
<a href="/downloads.php?os=windows&osvariant=windows-downloads&version=<?php echo urlencode($mver); ?>">
491+
Windows downloads
492+
</a>
493+
</li>
494+
</ul>
495+
496+
<a href="<?php echo $current_uri; ?>#gpg-<?php echo $mver; ?>">GPG Keys for PHP <?php echo $mver; ?></a>
497+
</div>
498+
<?php endforeach; ?>
499+
<?php endforeach; /* major releases loop end */ ?>
500+
<?php
501+
}
502+

include/gpg-keys.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2-
require __DIR__ . '/branches.inc';
2+
3+
use phpweb\Releases\Branches;
34

45
// GPG keys used for signing releases.
56

@@ -224,7 +225,7 @@ function gpg_key_get_branches(bool $activeOnly): array {
224225

225226
if (!$activeOnly) { return $branches; }
226227

227-
$active = get_active_branches();
228+
$active = Branches::active();
228229
return array_filter($branches, function ($branch) use ($active) {
229230
[$major] = explode('.', $branch, 2);
230231
return isset($active[$major][$branch]);

include/releases.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
$OLDRELEASES = array (
2+
return $OLDRELEASES = array (
33
8 =>
44
array (
55
'8.4.21' =>

0 commit comments

Comments
 (0)