Skip to content

Commit 2ca28f5

Browse files
committed
Attempt to eliminate all uses of the quasi-superglobal RELEASES and OLDRELEASES variables.
1 parent 2c8cea1 commit 2ca28f5

6 files changed

Lines changed: 121 additions & 103 deletions

File tree

bin/bumpRelease

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
(PHP_SAPI === 'cli') or die("Please run this script using the cli sapi");
44

55
require_once __DIR__ . "/../include/branches.inc";
6-
require_once __DIR__ . "/../include/version.inc";
7-
require_once __DIR__ . "/../include/releases.inc";
86

97
if ($_SERVER['argc'] < 1) {
108
fwrite(STDERR, "Usage: {$_SERVER['argv'][0]} major_version [ minor_version ]\n");
119
exit(1);
1210
}
1311

1412
$major = (int) $_SERVER['argv'][1];
15-
isset($RELEASES[$major]) or die("Unknown major version $major");
13+
isset(get_releases()[$major]) or die("Unknown major version $major");
1614
$minor = isset($_SERVER['argv'][2]) ? (int) $_SERVER['argv'][2] : null;
1715

1816
$version = get_current_release_for_branch($major, $minor);
19-
$info = $RELEASES[$major][$version] ?? null;
17+
$info = get_releases()[$major][$version] ?? null;
2018

2119
if ($info === null) {
2220
fwrite(STDERR, "Unable to find a current PHP release for {$major}.{$minor}\n");
@@ -34,7 +32,7 @@ $OLDRELEASES[$major] = array_merge(
3432
);
3533

3634
file_put_contents(__DIR__ . "/../include/releases.inc", [
37-
'<?php' . PHP_EOL . PHP_EOL . '$GLOBALS[\'OLDRELEASES\'] = $OLDRELEASES = ',
35+
'<?php' . PHP_EOL . PHP_EOL . 'return ',
3836
var_export($OLDRELEASES, true),
3937
";\n",
4038
]);

include/branches.inc

Lines changed: 109 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ function get_branch_overrides(): array
1414
return $cache ??= require __DIR__ . '/branch-overrides.inc';
1515
}
1616

17+
function get_releases(): array
18+
{
19+
static $cache = null;
20+
return $cache ??= require __DIR__ . '/version.inc';
21+
}
22+
23+
function get_old_releases(): array
24+
{
25+
static $cache = null;
26+
return $cache ??= require __DIR__ . '/releases.inc';
27+
}
28+
1729
function format_interval($from, DateTime $to) {
1830
try {
1931
$from_obj = $from instanceof DateTime ? $from : new DateTime($from);
@@ -73,7 +85,7 @@ function get_all_branches() {
7385

7486
$branches = [];
7587

76-
foreach ($GLOBALS['OLDRELEASES'] as $major => $releases) {
88+
foreach (get_old_releases() as $major => $releases) {
7789
foreach ($releases as $version => $release) {
7890
$branch = version_number_to_branch($version);
7991

@@ -86,7 +98,7 @@ function get_all_branches() {
8698
}
8799
}
88100

89-
foreach ($GLOBALS['RELEASES'] as $major => $releases) {
101+
foreach (get_releases() as $major => $releases) {
90102
foreach ($releases as $version => $release) {
91103
$branch = version_number_to_branch($version);
92104

@@ -111,7 +123,7 @@ function get_active_branches($include_recent_eols = true) {
111123
$branches = [];
112124
$now = new DateTime();
113125

114-
foreach ($GLOBALS['RELEASES'] as $major => $releases) {
126+
foreach (get_releases() as $major => $releases) {
115127
foreach ($releases as $version => $release) {
116128
$branch = version_number_to_branch($version);
117129

@@ -143,12 +155,14 @@ function get_active_branches($include_recent_eols = true) {
143155
* must be in $RELEASES _and_ must be the full version number, not the branch:
144156
* ie provide array('5.3.29'), not array('5.3'). */
145157
function get_eol_branches($always_include = null) {
158+
$release_data = get_releases();
159+
146160
$always_include = $always_include ?: [];
147161
$branches = [];
148162
$now = new DateTime();
149163

150164
// Gather the last release on each branch into a convenient array.
151-
foreach ($GLOBALS['OLDRELEASES'] as $major => $releases) {
165+
foreach (get_old_releases() as $major => $releases) {
152166
foreach ($releases as $version => $release) {
153167
$branch = version_number_to_branch($version);
154168

@@ -166,7 +180,7 @@ function get_eol_branches($always_include = null) {
166180

167181
/* Exclude releases from active branches, where active is defined as "in
168182
* the $RELEASES array and not explicitly marked as EOL there". */
169-
foreach ($GLOBALS['RELEASES'] as $major => $releases) {
183+
foreach ($release_data as $major => $releases) {
170184
foreach ($releases as $version => $release) {
171185
$branch = version_number_to_branch($version);
172186

@@ -191,8 +205,8 @@ function get_eol_branches($always_include = null) {
191205
$parts = explode('.', $version);
192206
$major = $parts[0];
193207

194-
if (isset($GLOBALS['RELEASES'][$major][$version])) {
195-
$release = $GLOBALS['RELEASES'][$major][$version];
208+
if (isset($release_data[$major][$version])) {
209+
$release = $release_data[$major][$version];
196210
$branch = version_number_to_branch($version);
197211

198212
if ($branch) {
@@ -219,14 +233,17 @@ function get_eol_branches($always_include = null) {
219233
* return either null (if no release exists on the given branch), or the usual
220234
* version metadata from $RELEASES for a single release. */
221235
function get_initial_release($branch) {
236+
$release_data = get_releases();
237+
$old_release_data = get_old_releases();
238+
222239
$branch = version_number_to_branch($branch);
223240
if (!$branch) {
224241
return null;
225242
}
226243
$major = substr($branch, 0, strpos($branch, '.'));
227244

228-
if (isset($GLOBALS['OLDRELEASES'][$major]["$branch.0"])) {
229-
return $GLOBALS['OLDRELEASES'][$major]["$branch.0"];
245+
if (isset($old_release_data[$major]["$branch.0"])) {
246+
return $old_release_data[$major]["$branch.0"];
230247
}
231248

232249
$overrides = get_branch_overrides();
@@ -236,9 +253,9 @@ function get_initial_release($branch) {
236253

237254
/* If there's only been one release on the branch, it won't be in
238255
* $OLDRELEASES yet, so let's check $RELEASES. */
239-
if (isset($GLOBALS['RELEASES'][$major]["$branch.0"])) {
256+
if (isset($release_data[$major]["$branch.0"])) {
240257
// Fake a date like we have on the oldreleases array.
241-
$release = $GLOBALS['RELEASES'][$major]["$branch.0"];
258+
$release = $release_data[$major]["$branch.0"];
242259
$release['date'] = $release['source'][0]['date'];
243260
return $release;
244261
}
@@ -248,28 +265,31 @@ function get_initial_release($branch) {
248265
}
249266

250267
function get_final_release($branch) {
268+
$release_data = get_releases();
269+
$old_release_data = get_old_releases();
270+
251271
$branch = version_number_to_branch($branch);
252272
if (!$branch) {
253273
return null;
254274
}
255275
$major = substr($branch, 0, strpos($branch, '.'));
256276

257277
$last = "$branch.0";
258-
foreach ($GLOBALS['OLDRELEASES'][$major] as $version => $release) {
278+
foreach ($old_release_data[$major] as $version => $release) {
259279
if (version_number_to_branch($version) == $branch && version_compare($version, $last, '>')) {
260280
$last = $version;
261281
}
262282
}
263283

264-
if (isset($GLOBALS['OLDRELEASES'][$major][$last])) {
265-
return $GLOBALS['OLDRELEASES'][$major][$last];
284+
if (isset($old_release_data[$major][$last])) {
285+
return $old_release_data[$major][$last];
266286
}
267287

268288
/* If there's only been one release on the branch, it won't be in
269289
* $OLDRELEASES yet, so let's check $RELEASES. */
270-
if (isset($GLOBALS['RELEASES'][$major][$last])) {
290+
if (isset($release_data[$major][$last])) {
271291
// Fake a date like we have on the oldreleases array.
272-
$release = $GLOBALS['RELEASES'][$major][$last];
292+
$release = $release_data[$major][$last];
273293
$release['date'] = $release['source'][0]['date'];
274294
return $release;
275295
}
@@ -401,24 +421,94 @@ function version_array(string $version, ?int $length = null)
401421

402422
//#[Deprecated('Use VersionData->latestRelease')]
403423
function get_current_release_for_branch(int $major, ?int $minor): ?string {
404-
global $RELEASES, $OLDRELEASES;
424+
$release_data = get_releases();
425+
$old_release_data = get_old_releases();
405426

406427
$prefix = "{$major}.";
407428
if ($minor !== null) {
408429
$prefix .= "{$minor}.";
409430
}
410431

411-
foreach (($RELEASES[$major] ?? []) as $version => $_) {
432+
foreach (($release_data[$major] ?? []) as $version => $_) {
412433
if (!strncmp($prefix, $version, strlen($prefix))) {
413434
return $version;
414435
}
415436
}
416437

417-
foreach (($OLDRELEASES[$major] ?? []) as $version => $_) {
438+
foreach (($old_release_data[$major] ?? []) as $version => $_) {
418439
if (!strncmp($prefix, $version, strlen($prefix))) {
419440
return $version;
420441
}
421442
}
422443

423444
return null;
424445
}
446+
447+
448+
// Get latest release version and info.
449+
function release_get_latest() {
450+
$version = '0.0.0';
451+
$current = null;
452+
foreach (get_releases() as $versions) {
453+
foreach ($versions as $ver => $info) {
454+
if (version_compare($ver, $version) > 0) {
455+
$version = $ver;
456+
$current = $info;
457+
}
458+
}
459+
}
460+
461+
return [$version, $current];
462+
}
463+
464+
function show_source_releases()
465+
{
466+
$SHOW_COUNT = 4;
467+
468+
$current_uri = htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8');
469+
470+
$i = 0; foreach (get_releases() as $MAJOR => $major_releases): /* major releases loop start */
471+
$releases = array_slice($major_releases, 0, $SHOW_COUNT);
472+
?>
473+
<a id="v<?php echo $MAJOR; ?>"></a>
474+
<?php foreach ($releases as $v => $a): ?>
475+
<?php $mver = substr($v, 0, strrpos($v, '.')); ?>
476+
<?php $stable = $i++ === 0 ? "Current Stable" : "Old Stable"; ?>
477+
478+
<h3 id="v<?php echo $v; ?>" class="title">
479+
<span class="release-state"><?php echo $stable; ?></span>
480+
PHP <?php echo $v; ?>
481+
(<a href="/ChangeLog-<?php echo $MAJOR; ?>.php#<?php echo urlencode($v); ?>" class="changelog">Changelog</a>)
482+
</h3>
483+
<div class="content-box">
484+
485+
<ul>
486+
<?php foreach ($a['source'] as $rel): ?>
487+
<li>
488+
<?php download_link($rel['filename'], $rel['filename']); ?>
489+
<span class="releasedate"><?php echo date('d M Y', strtotime($rel['date'])); ?></span>
490+
<?php
491+
if (isset($rel['md5'])) echo '<span class="md5sum">', $rel['md5'], '</span>';
492+
if (isset($rel['sha256'])) echo '<span class="sha256">', $rel['sha256'], '</span>';
493+
?>
494+
<?php if (isset($rel['note']) && $rel['note']): ?>
495+
<p>
496+
<strong>Note:</strong>
497+
<?php echo $rel['note']; ?>
498+
</p>
499+
<?php endif; ?>
500+
</li>
501+
<?php endforeach; ?>
502+
<li>
503+
<a href="/downloads.php?os=windows&osvariant=windows-downloads&version=<?php echo urlencode($mver); ?>">
504+
Windows downloads
505+
</a>
506+
</li>
507+
</ul>
508+
509+
<a href="<?php echo $current_uri; ?>#gpg-<?php echo $mver; ?>">GPG Keys for PHP <?php echo $mver; ?></a>
510+
</div>
511+
<?php endforeach; ?>
512+
<?php endforeach; /* major releases loop end */ ?>
513+
<?php
514+
}

include/version.inc

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* ),
1616
* );
1717
*/
18-
$GLOBALS['RELEASES'] = $RELEASES = (function () {
18+
return (function () {
1919
$data = [];
2020

2121
/* PHP 8.5 Release */
@@ -91,75 +91,3 @@ $GLOBALS['RELEASES'] = $RELEASES = (function () {
9191
}
9292
return $ret;
9393
})();
94-
95-
// Get latest release version and info.
96-
function release_get_latest() {
97-
global $RELEASES;
98-
99-
$version = '0.0.0';
100-
$current = null;
101-
foreach ($RELEASES as $versions) {
102-
foreach ($versions as $ver => $info) {
103-
if (version_compare($ver, $version) > 0) {
104-
$version = $ver;
105-
$current = $info;
106-
}
107-
}
108-
}
109-
110-
return [$version, $current];
111-
}
112-
113-
function show_source_releases()
114-
{
115-
global $RELEASES;
116-
117-
$SHOW_COUNT = 4;
118-
119-
$current_uri = htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8');
120-
121-
$i = 0; foreach ($RELEASES as $MAJOR => $major_releases): /* major releases loop start */
122-
$releases = array_slice($major_releases, 0, $SHOW_COUNT);
123-
?>
124-
<a id="v<?php echo $MAJOR; ?>"></a>
125-
<?php foreach ($releases as $v => $a): ?>
126-
<?php $mver = substr($v, 0, strrpos($v, '.')); ?>
127-
<?php $stable = $i++ === 0 ? "Current Stable" : "Old Stable"; ?>
128-
129-
<h3 id="v<?php echo $v; ?>" class="title">
130-
<span class="release-state"><?php echo $stable; ?></span>
131-
PHP <?php echo $v; ?>
132-
(<a href="/ChangeLog-<?php echo $MAJOR; ?>.php#<?php echo urlencode($v); ?>" class="changelog">Changelog</a>)
133-
</h3>
134-
<div class="content-box">
135-
136-
<ul>
137-
<?php foreach ($a['source'] as $rel): ?>
138-
<li>
139-
<?php download_link($rel['filename'], $rel['filename']); ?>
140-
<span class="releasedate"><?php echo date('d M Y', strtotime($rel['date'])); ?></span>
141-
<?php
142-
if (isset($rel['md5'])) echo '<span class="md5sum">', $rel['md5'], '</span>';
143-
if (isset($rel['sha256'])) echo '<span class="sha256">', $rel['sha256'], '</span>';
144-
?>
145-
<?php if (isset($rel['note']) && $rel['note']): ?>
146-
<p>
147-
<strong>Note:</strong>
148-
<?php echo $rel['note']; ?>
149-
</p>
150-
<?php endif; ?>
151-
</li>
152-
<?php endforeach; ?>
153-
<li>
154-
<a href="/downloads.php?os=windows&osvariant=windows-downloads&version=<?php echo urlencode($mver); ?>">
155-
Windows downloads
156-
</a>
157-
</li>
158-
</ul>
159-
160-
<a href="<?php echo $current_uri; ?>#gpg-<?php echo $mver; ?>">GPG Keys for PHP <?php echo $mver; ?></a>
161-
</div>
162-
<?php endforeach; ?>
163-
<?php endforeach; /* major releases loop end */ ?>
164-
<?php
165-
}

releases/feed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
ob_start();
2323

2424
// Flatten major versions out of RELEASES.
25-
$RELEASED_VERSIONS = array_reduce($RELEASES, 'array_merge', []);
25+
$RELEASED_VERSIONS = array_reduce(get_releases(), 'array_merge', []);
2626
$FEED_UPDATED = 0;
2727
krsort($RELEASED_VERSIONS);
2828
foreach ($RELEASED_VERSIONS as $version => $release) {

releases/index.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
include_once __DIR__ . "/../include/branches.inc";
66

77
if (isset($_GET["serialize"]) || isset($_GET["json"])) {
8+
$RELEASES = get_releases();
9+
$OLDRELEASES = get_old_releases();
10+
811
$RELEASES = $RELEASES + $OLDRELEASES;
912

1013
$machineReadable = [];

0 commit comments

Comments
 (0)