Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions public/releases/branch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

$_SERVER['BASE_PAGE'] = 'releases/branch.php';

require_once __DIR__ . '/../../include/prepend.inc';
require_once __DIR__ . '/../../include/branches.inc';

$branch = $_GET['version'] ?? '';
if ($branch === '') {
header('Location: /supported-versions.php');
exit;
}

$branches = get_all_branches();
if (!is_string($branch)
|| !preg_match('/\A([0-9]+)\.[0-9]+\z/', $branch, $matches)
|| !isset($branches[$matches[1]][$branch])
) {
http_response_code(404);
site_header('PHP Release Branch Not Found');
?>
<h1>PHP Release Branch Not Found</h1>
<p>See the <a href="/supported-versions.php">supported versions</a> for available branches.</p>
<?php
site_footer();
return;
}

$release = $branches[$matches[1]][$branch];
$state = get_branch_support_state($branch);
$status = match ($state) {
'stable' => 'Active support',
'security' => 'Security fixes only',
'eol' => 'End of life',
'future' => 'Upcoming',
default => 'Unknown',
};
$latest = $release['version'];
$dates = ['Initial release' => get_branch_release_date($branch)];
if (version_compare($branch, '5.3', '>=')) {
$dates['Active support ends'] = get_branch_bug_eol_date($branch);
$dates['Security support ends'] = get_branch_security_eol_date($branch);
} else {
// The historical data records the final release as the end of life.
$dates['End of life'] = get_branch_security_eol_date($branch);
if ($state === null && $dates['End of life'] !== null) {
$status = 'End of life';
}
}

site_header("PHP $branch Release");
?>

<h1>PHP <?= htmlspecialchars($branch) ?> Release</h1>

<dl>
<dt>Support status</dt>
<dd><?= htmlspecialchars($status) ?></dd>
<dt>Latest release</dt>
<dd><?= htmlspecialchars($latest) ?></dd>
<?php foreach ($dates as $label => $date): ?>
<dt><?= htmlspecialchars($label) ?></dt>
<dd>
<?php if ($date !== null): ?>
<time datetime="<?= $date->format('Y-m-d') ?>"><?= $date->format('j M Y') ?></time>
<?php else: ?>
Unknown
<?php endif; ?>
</dd>
<?php endforeach; ?>
</dl>

<ul>
<?php if ($status === 'End of life'): ?>
<li><a href="/releases/">Old source archives</a></li>
<?php elseif ($state === 'stable' || $state === 'security'): ?>
<li><a href="/downloads.php?version=<?= rawurlencode($branch) ?>">Download PHP <?= htmlspecialchars($branch) ?></a></li>
<?php endif; ?>
<?php if (is_file(__DIR__ . "/$branch/index.php")): ?>
<li><a href="/releases/<?= rawurlencode($branch) ?>/">What's new in PHP <?= htmlspecialchars($branch) ?></a></li>
<?php endif; ?>
<li><a href="/supported-versions.php">Supported versions</a></li>
</ul>

<?php site_footer(); ?>
2 changes: 1 addition & 1 deletion public/supported-versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
?>
<tr class="<?php echo $state ?>">
<td>
<a href="/downloads.php?version=<?php echo htmlspecialchars($branch) ?>"><?php echo htmlspecialchars($branch) ?></a>
<a href="/releases/branch.php?version=<?php echo rawurlencode($branch) ?>"><?php echo htmlspecialchars($branch) ?></a>
</td>
<td><?php echo htmlspecialchars($initial->format('j M Y')) ?></td>
<td class="collapse-phone"><em><?php echo htmlspecialchars(format_interval($initial, $now)) ?></em></td>
Expand Down
64 changes: 64 additions & 0 deletions tests/EndToEnd/ReleaseBranchTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace phpweb\Test\EndToEnd;

use DOMDocument;
use DOMElement;
use DOMNodeList;
use DOMXPath;
use PHPUnit\Framework;

#[Framework\Attributes\CoversNothing]
final class ReleaseBranchTest extends Framework\TestCase
{
public function testSupportedVersionsLinkToBranchSupportDetails(): void
{
$listing = $this->getPage('/supported-versions.php', 200);
$rows = $listing->query('//table[thead/tr/th = "Branch"]/tbody/tr');
self::assertInstanceOf(DOMNodeList::class, $rows);
self::assertGreaterThan(0, $rows->length);

foreach ($rows as $row) {
self::assertInstanceOf(DOMElement::class, $row);
$branch = trim((string) $listing->evaluate('string(td[1]/a)', $row));
$href = $listing->evaluate('string(td[1]/a/@href)', $row);
self::assertIsString($href);
self::assertSame('/releases/branch.php?version=' . $branch, $href);

$details = $this->getPage($href, 200);
self::assertSame('PHP ' . $branch . ' Release', $details->evaluate('string(//h1)'));
$supportDates = $details->query('//dl/dd/time');
self::assertInstanceOf(DOMNodeList::class, $supportDates);
self::assertCount(3, $supportDates);
foreach ([2, 4, 6] as $index => $column) {
$date = $supportDates->item($index);
self::assertInstanceOf(DOMElement::class, $date);
self::assertSame(
trim((string) $listing->evaluate("string(td[$column])", $row)),
$date->textContent,
);
}
}
}

public function testUnknownBranchReturnsNotFound(): void
{
$this->getPage('/releases/branch.php?version=999.999', 404);
}

private function getPage(string $path, int $status): DOMXPath
{
$handle = curl_init('http://' . getenv('HTTP_HOST') . $path);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$body = curl_exec($handle);
self::assertSame($status, curl_getinfo($handle, CURLINFO_HTTP_CODE), $path);
self::assertIsString($body);

$document = new DOMDocument();
self::assertTrue($document->loadHTML($body, LIBXML_NOERROR | LIBXML_NOWARNING));

return new DOMXPath($document);
}
}