2025-12-13 10:59:52 -05:00

64 lines
1.4 KiB
PHP

<?php
require_once __DIR__ . '/vendor/autoload.php';
use Aoc2025\Days\Day1;
use Aoc2025\Days\Day2;
use Aoc2025\Days\Day3;
use Aoc2025\Services\Template;
// First check if this is solution page request.
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
if (str_starts_with($path, '/solutions')) {
$path_exploded = explode('/', $path);
if (count($path_exploded) < 3) {
header('Location: /');
}
$day = str_replace("-", '', $path_exploded[2]);
$day = ucfirst($day);
try {
$code = @file_get_contents(__DIR__ . '/src/Days/' . $day . '.php');
if (!$code) {
throw new Exception('File not found');
}
else {
echo "<pre><code class='language-php'>" . htmlspecialchars($code) . "</code></pre>";
}
}
catch (Exception $e) {
header('Location: /');
}
return;
}
if ($path != '/') {
header('Location: /');
}
// Day 1.
$day_1 = new Day1();
$day_1_answer = $day_1->run();
// Day 2.
$day_2 = new Day2();
$day_2_answer = $day_2->run();
// Day 3.
$day_3 = new Day3();
$day_3_answer = $day_3->run();
// Render the template.
$template = new Template('main.html');
$substitutions = [
'day_1_answer' => $day_1_answer['part_1'],
'day_1_answer_2' => $day_1_answer['part_2'],
'day_2_answer' => $day_2_answer['part_1'],
'day_2_answer_2' => $day_2_answer['part_2'],
'day_3_answer' => $day_3_answer['part_1'],
'day_3_answer_2' => $day_3_answer['part_2'],
];
$response = $template->render($substitutions);
echo $response;