Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Commit 6959152

Browse files
committed
Display last update on main page
1 parent 51d485a commit 6959152

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Controller/DefaultController.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,34 @@
44

55
namespace App\Controller;
66

7+
use App\Repository\LastUpdateRepository;
78
use Symfony\Component\HttpFoundation\Response;
89

910
final class DefaultController
1011
{
12+
public function __construct(
13+
private LastUpdateRepository $repository,
14+
) {
15+
}
16+
1117
public function index(): Response
1218
{
19+
$lastUpdate = $this->repository->get()->format('Y-m-d H:i:s');
20+
1321
return new Response(<<<HTML
1422
<html>
1523
<head>
1624
<title>phpversions</title>
1725
</head>
1826
<body>
19-
An API that expose all PHP versions:
27+
<p>An API that expose all PHP versions:</p>
2028
<ul>
2129
<li><a href="/all.json">All main PHP versions</a></li>
2230
<li><a href="/releases.json">All PHP releases versions</a></li>
2331
<li><a href="/current.json">Maintened versions</a></li>
2432
<li><a href="/eol.json">Unmainted versions</a></li>
2533
</ul>
34+
<p>Last update: $lastUpdate</p>
2635
</body>
2736
</html>
2837
HTML

src/Repository/LastUpdateRepository.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ public function __construct(
1717
) {
1818
}
1919

20+
public function get(): DateTimeImmutable
21+
{
22+
$stmt = $this->db->query('SELECT * FROM last_update;');
23+
24+
return new DateTimeImmutable($stmt->fetchColumn());
25+
}
26+
2027
public function save(): void
2128
{
2229
$this->db->beginTransaction();

0 commit comments

Comments
 (0)