filesystem = $filesystem; $this->metas = $metas; } /** @return DocumentNode[] */ public function getAll(): array { return $this->documents; } public function hasDocument(string $file): bool { return isset($this->documents[$file]); } public function addDocument(string $file, DocumentNode $document): void { $this->documents[$file] = $document; } public function render(string $targetDirectory): void { foreach ($this->documents as $file => $document) { $target = $this->getTargetOf($targetDirectory, $file); $directory = dirname($target); if (! is_dir($directory)) { $this->filesystem->mkdir($directory, 0755); } $this->filesystem->dumpFile($target, $document->renderDocument()); } } private function getTargetOf(string $targetDirectory, string $file): string { $metaEntry = $this->metas->get($file); if ($metaEntry === null) { throw new InvalidArgumentException(sprintf('Could not find target file for %s', $file)); } return $targetDirectory . '/' . $metaEntry->getUrl(); } }