/** * @param Root $root * * @return Root */ private function hydrateDirectory(Root $root) { $basePath = $root->getBasePath(); foreach ($root->getFileCollection() as $file) { $dirpath = $file->getDirectory($basePath); if ($root->hasDirectory($dirpath)) { $directory = $root->getDirectoryByName($dirpath); } else { $directory = new Directory(); $directory->setPath($dirpath); } $directory->addFile($file); $root->addDirectory($directory); } return $root; }
/** * @param Root $root * @param string $target * @param string $templatePath */ public function render(Root $root, $target, $templatePath = false) { if ($templatePath === false) { $templatePath = __DIR__ . '/Template/'; } $twig = $this->twigCreator->createInstance($templatePath); foreach ($root->getFileCollection() as $file) { $this->renderFile($file, $twig, $target, $root->getBasePath()); } foreach ($root->getDirectoryCollection() as $directory) { $this->renderDirectory($directory, $root, $twig, $target); foreach ($directory->getFileCollection() as $file) { $this->renderFile($file, $twig, $target, $root->getBasePath()); } } $this->copyAssets($templatePath, $target); }