Skip to content

Commit 72cf0eb

Browse files
committed
Create news Days from Template
1 parent a73c46e commit 72cf0eb

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/Days/DayTemplate.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Failedcode\Aoc2022\Days;
4+
5+
class DayTemplate extends AbstractDay
6+
{
7+
public function solve_part_1(): string
8+
{
9+
$inputList = $this->util->loadInput($DAY);
10+
return "TODO";
11+
}
12+
13+
public function solve_part_2(): string
14+
{
15+
return "TODO";
16+
}
17+
}

src/Utils.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,24 @@ protected function loadDotEnv()
8282
}
8383
}
8484
}
85+
86+
/**
87+
* @param int $day
88+
* @return void
89+
*/
90+
public function createDayFromTemplate($day)
91+
{
92+
$templateFile = __dir__ . '/Days/DayTemplate.php';
93+
$classReplace = "Day{$day}";
94+
$classFind = basename($templateFile, '.php');
95+
$destinationFilepath = dirname($templateFile) . "/$classReplace.php";
96+
97+
if (file_exists($destinationFilepath)) {
98+
return;
99+
}
100+
101+
$content = file_get_contents($templateFile);
102+
$content = str_replace([$classFind, '$DAY'], [$classReplace, $day], $content);
103+
file_put_contents($destinationFilepath, $content);
104+
}
85105
}

src/aoc.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@
1010
if ($day === 0) {
1111
$day = (int)strftime('%d');
1212
}
13+
if ($day < 1 || $day > 25) {
14+
echo "Day {$day} not supported!\n";
15+
exit(0);
16+
}
1317

1418
$solverClass = "\Failedcode\Aoc2022\Days\Day{$day}";
1519
/** @var \Failedcode\Aoc2022\Days\AbstractDay $solver */
1620
if (!class_exists($solverClass)) {
21+
$uitls = new \Failedcode\Aoc2022\Utils();
22+
$uitls->createDayFromTemplate($day);
23+
$uitls->loadInput($day);
1724
echo "Day {$day} not yet implemented!\n";
1825
exit(0);
1926
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy