dataPath . '*.md'); assert(is_array($fileNames)); return array_map(function (string $name): MarkdownPage { usleep(100000); $content = file_get_contents($name); $name = str_replace($this->dataPath, '', $name); $name = str_replace('.md', '', $name); $id = (int) substr($name, 0, 2); $title = substr($name, 3); return new MarkdownPage($id, $title, $content); }, $fileNames); } public function byId(int $id): MarkdownPage { $callback = fn (MarkdownPage $p): bool => $p->id === $id; $filtered = array_values(array_filter($this->all(), $callback)); if (count($filtered) === 0) { throw new NotFound; } return $filtered[0]; } public function byTitle(string $title): MarkdownPage { $callback = fn (MarkdownPage $p): bool => $p->title === $title; $filtered = array_values(array_filter($this->all(), $callback)); if (count($filtered) === 0) { throw new NotFound; } return $filtered[0]; } }