-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.php
More file actions
28 lines (19 loc) · 826 Bytes
/
app.php
File metadata and controls
28 lines (19 loc) · 826 Bytes
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
<?php
use function Laravel\Prompts\select;
require_once 'vendor/autoload.php';
$tasks = glob('src/Tasks/*/*.php');
$registeredTasks = collect();
foreach ($tasks as $task) {
if (str_contains($task, 'Task.php')) {
$fullClassName = str_replace(['src/', '/', '.php'], ['', '\\', ''], 'TomEasterbrook\\AdventOfCode\\'.$task);
if (class_exists($fullClassName)) {
$registeredTasks->add(new $fullClassName);
}
}
}
echo "Welcome to Tom's Advent of Code 2024\n";
$options = $registeredTasks->map(fn ($task) => "{$task->getDay()}: {$task->getName()}")->toArray();
$selectedTask = select('Please select a task to run', $options);
$task = $registeredTasks->filter(fn ($task) => "{$task->getDay()}: {$task->getName()}" === $selectedTask)->first();
$task->run();
echo "Task completed\n";