-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
35 lines (28 loc) · 1.03 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use PwC\RouteFinder\CountriesApiClient;
use PwC\RouteFinder\AppCacheEngine;
use PwC\RouteFinder\AppQueryEngine;
use Symfony\Component\HttpKernel\Log\Logger as AppLogger;
use Symfony\Component\HttpFoundation\JsonResponse;
$input = array_values(array_filter(explode('/', $_SERVER['PATH_INFO'] ?? getenv('SERVER_PATH'))));
// If the input is accepted, here we bootstrap the whole app.
$data = [];
if (count($input) === 2) {
$cache = new AppCacheEngine();
$logger = new AppLogger(output: __DIR__ . '/app.log');
$api = new CountriesApiClient(
cache: $cache,
logger: $logger,
);
$engine = new AppQueryEngine(api: $api, cache: $cache);
[$origin, $destination] = $input;
try {
$data = $engine->findPath($origin, $destination);
} catch (Throwable $e) {
$logger->critical("Not handled case, keep working.");
$logger->error($e);
}
}
(new JsonResponse(status: $data ? 200 : 400))->setData($data)->send();