/** * Generate markdown documentation. * * @param Structure $structure The structure * @param string $outputPath The directory path where to put markdown documentation * * @throws DocMdException * @throws \Twig_Error_Loader * @throws \Twig_Error_Runtime * @throws \Twig_Error_Syntax */ protected function generateDocs(Structure $structure, $outputPath) { foreach ($structure->getFiles() as $file) { $class = $file->getClass(); $classFullName = $class->getFullName(); if (in_array($classFullName, $this->config['exclude'])) { continue; } $this->classes[$classFullName] = $class; switch ($class->getClassType()) { case File::TYPE_CLASS: $this->index['classes'][] = Tools::getFileLink($classFullName); break; case File::TYPE_INTERFACE: $this->index['interfaces'][] = Tools::getFileLink($classFullName); break; case File::TYPE_TRAIT: $this->index['traits'][] = Tools::getFileLink($classFullName); break; } } $loader = new Twig_Loader_Filesystem($this->tplDir); $twig = new Twig_Environment($loader); foreach ($this->classes as $class) { $doc = $twig->render('class.txt', ['class' => $class]); file_put_contents($outputPath . DIRECTORY_SEPARATOR . $class->getMdFileName(), $doc); } $twig = new Twig_Environment($loader); $doc = $twig->render('index.txt', ['classes' => $this->index['classes'], 'interfaces' => $this->index['interfaces'], 'traits' => $this->index['traits'], 'projectName' => $this->config['project_name']]); file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'index.md', $doc); }