summaryrefslogtreecommitdiff
path: root/2024/OCaml/lib/day_04/php/Input.php
blob: f7e03c14b7f2124817ff0456f9ffdb87c2df62c1 (plain)
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
<?php

declare(strict_types=1);

class Input
{
	public string $contents;

	public function __construct(private string $fileName)
	{
		$contents = file_get_contents($this->fileName, use_include_path: true);
		$this->contents = $contents === false ? "" : $contents;
	}

	public function toGrid(): Grid
	{
		$lines = explode("\n", $this->contents);
		$gridArray = array_map(
			callback: fn(string $line): array => str_split(trim($line)),
			array: $lines
		);

		return new Grid($gridArray);
	}
}