saggre/phpdocumentor-markdown
phpDocumentor Markdown template that generates GitHub/GitLab-ready docs from PHP source. Documents classes, interfaces, traits, functions, methods, properties, types, modifiers, and inheritance. Run phpdoc with the template to output Markdown for repos, wikis, or AI context.
header.md.twig, class.md.twig) allows for customization without deep integration into Laravel’s core./docs folders.composer require --dev saggre/phpdocumentor-markdown).--template flag pointing to the template path.php artisan docs:generate).| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| phpDocumentor3 Support | The package targets phpDocumentor3, which is legacy (phpDocumentor4 is the active branch). Risk of deprecated features or incompatibility with newer Laravel/PHP versions. | - Pin phpDocumentor3 to a stable version (e.g., 3.6.x) in composer.json.- Monitor phpDocumentor’s roadmap for migration paths to phpDocumentor4. |
| Template Customization | Overriding Twig templates may require Twig expertise. Poorly formatted templates could break Markdown rendering. | - Start with default templates and incrementally customize.- Use GitHub/GitLab’s Markdown preview for validation. |
| GitHub Wiki Limitation | GitHub wikis use a flat structure, breaking internal links. GitLab wikis work natively. | - Target GitLab wikis or static /docs folders for GitHub.- Use relative paths in templates for local file linking. |
| CI/CD Complexity | Adding a documentation generation step to CI pipelines may introduce build time overhead. | - Cache vendor/ directory in CI.- Run docs generation in a separate job (e.g., only on main branch or tags). |
| AI Integration | While Markdown is useful for AI, structured data (JSON/YAML) may be better for advanced use cases (e.g., code completion tools). | - Export docs as both Markdown and JSON (e.g., using phpDocumentor’s --format=json alongside Markdown).- Use tools like phpDocumentor-to-markdown for hybrid outputs. |
Documentation Strategy:
Toolchain Compatibility:
/docs) or hosted externally (e.g., GitHub Pages)?Customization Needs:
@route, @middleware)?Maintenance:
Performance:
Laravel Compatibility:
php artisan docs:generate) for Laravel-specific workflows.Toolchain Synergy:
| Tool/Library | Integration Path |
|---|---|
| Composer | Install via composer require --dev saggre/phpdocumentor-markdown. |
| phpDocumentor3 | Run via CLI: phpdoc --directory=src --target=docs --template="vendor/saggre/phpdocumentor-markdown/themes/markdown". |
| GitHub/GitLab | Push generated Markdown to wiki or /docs folder. GitLab wikis work natively; GitHub requires manual link fixes. |
| CI/CD (GitHub Actions/GitLab CI) | Add a step to generate docs on push/tag (e.g., using phpDocumentor Docker image). |
| AI Tools | Use generated Markdown as prompt context for GitHub Copilot or custom LLMs. |
| Laravel Artisan | Create a custom command to abstract the CLI call (see example below). |
| Laravel Blade | Serve docs via routes (e.g., Route::get('/docs', fn() => view('docs.index'))) and render Markdown with a package like spatie/markdown. |
Assessment Phase:
Pilot Integration:
composer require --dev saggre/phpdocumentor-markdown
phpdoc --directory=src --target=docs --template="vendor/saggre/phpdocumentor-markdown/themes/markdown"
/docs folder.Laravel-Specific Setup:
app/Console/Commands/GenerateDocs.php:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class GenerateDocs extends Command
{
protected $signature = 'docs:generate {--directory=src : Source directory} {--target=docs : Output directory}';
protected $description = 'Generate Markdown docs using phpDocumentor';
public function handle()
{
$directory = $this->option('directory');
$target = $this->option('target');
$template = __DIR__ . '/../../../vendor/saggre/phpdocumentor-markdown/themes/markdown';
$this->info("Generating docs from {$directory} to {$target}...");
shell_exec("phpdoc --directory={$directory} --target={$target} --template={$template}");
$this->info('Docs generated successfully!');
}
}
Register in app/Console/Kernel.php:
protected $commands = [
Commands\GenerateDocs::class,
];
Run with:
php artisan docs:generate
composer.json:
"
How can I help you explore Laravel packages today?