dataPath . '*.md'); if ($files === false) { throw new InternalServerError('cannot read pages'); } return array_map(function (string $filename) { $content = file_get_contents($filename); if ($content === false) { throw new InternalServerError('cannot read pages'); } $idAndTitle = str_replace([$this->dataPath, '.md'], ['', ''], $filename); return new MarkdownPage( (int) substr($idAndTitle, 0, 2), substr($idAndTitle, 3), $content ); }, $files); } public function byName(string $name): MarkdownPage { $pages = array_values( array_filter( $this->all(), fn (MarkdownPage $p) => $p->title === $name, ) ); if (count($pages) !== 1) { throw new NotFound; } return $pages[0]; } }