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

Commit 09e001a

Browse files
committed
Add status route
1 parent 25d4f5d commit 09e001a

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

config/routes.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ index:
33
methods: [GET]
44
controller: App\Controller\DefaultController::index
55

6+
status:
7+
path: /status
8+
controller: App\Controller\StatusController
9+
610
versions_all:
711
path: /all.{_format}
812
methods: [GET]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Controller;
6+
7+
use App\PDOFactory;
8+
use PDO;
9+
use PDOException;
10+
use Symfony\Component\HttpFoundation\Response;
11+
12+
class StatusController
13+
{
14+
public function __construct(
15+
private PDOFactory $factory,
16+
) {
17+
}
18+
19+
public function __invoke(): Response
20+
{
21+
try {
22+
$db = $this->factory->create();
23+
} catch (PDOException) {
24+
return new Response('FAILED: database connection error.', Response::HTTP_INTERNAL_SERVER_ERROR);
25+
}
26+
27+
if (false === $db->exec('SELECT 1')) {
28+
return new Response('FAILED: database access error.', Response::HTTP_INTERNAL_SERVER_ERROR);
29+
}
30+
31+
return new Response('OK', Response::HTTP_OK);
32+
}
33+
}

0 commit comments

Comments
 (0)