cvuorinen/phpdoc-markdown-public
Generate clean Markdown documentation from PHPDoc comments for public APIs. Extracts classes, methods, and types into readable docs for packages and projects, helping you publish consistent reference docs directly from your codebase.
Installation Add the package via Composer:
composer require --dev cvuorinen/phpdoc-markdown-public
Ensure phpDocumentor is installed globally or via Composer:
composer global require phpdocumentor/phpdocumentor
First Use Case Generate Markdown docs for a Laravel project:
vendor/bin/phpdoc -d ./app -t ./docs/api --template cvuorinen/phpdoc-markdown-public
-d: Source directory (e.g., ./app for Laravel models/controllers).-t: Output directory (e.g., ./docs/api).--template: Specify the Markdown template.Where to Look First
vendor/cvuorinen/phpdoc-markdown-public/config.php for customization options.Models/User.md).app/Http/Controllers/, app/Models/, and app/Services/ for public API docs.CI/CD Integration
Add a script to composer.json for automated doc generation:
"scripts": {
"docs": "php vendor/bin/phpdoc -d ./app -t ./docs/api --template cvuorinen/phpdoc-markdown-public"
}
Trigger via:
composer docs
gh-pages branch or Netlify.Laravel-Specific Patterns
/**
* @OA\Get(
* path="/api/users",
* summary="Get all users",
* @OA\Response(response="200", description="List of users")
* )
*/
public function index() { ... }
@property and @method tags for Eloquent methods:
/**
* @property int $id
* @method static \Illuminate\Database\Eloquent\Collection|User[] all()
*/
class User extends Model { ... }
Custom Templates
Extend the template by copying vendor/cvuorinen/phpdoc-markdown-public to templates/phpdoc-markdown-custom and modifying:
config.php: Adjust Markdown formatting (e.g., enable/disable @see links).theme/: Override CSS/JS for styling (e.g., add Laravel-specific badges).Integration with Laravel Tools
vendor/bin/php artisan ide-helper:generate
Namespace Collisions
App\Models\User vs. App\Services\User).--ignore to exclude directories:
vendor/bin/phpdoc -d ./app --ignore=*/Tests/* -t ./docs/api
PHPDoc Parsing Quirks
@OA\*) may not render correctly.Performance
vendor/bin/phpdoc -d ./app/Http -t ./docs/api
Template Caching
config.php require re-running phpdoc.--cache for faster subsequent runs (but clear cache if configs change):
vendor/bin/phpdoc --cache ./phpdoc-cache
vendor/bin/phpdoc -vvv
--parse-only to validate PHPDoc parsing:
vendor/bin/phpdoc --parse-only -d ./app
Custom Markdown Processors
Hook into the template’s MarkdownProcessor class to modify output (e.g., add Laravel-specific syntax highlighting):
// In a custom template's config.php
$template->setProcessor(new \MyApp\CustomMarkdownProcessor());
Post-Processing Scripts Use a script to transform Markdown after generation (e.g., add table of contents):
# Example: Add TOC to each file
find ./docs/api -name "*.md" -exec sed -i '/^#/!b;n;I\\[TOC\\]\n' {} \;
Git Hooks
Auto-generate docs on pre-commit (for critical paths):
# In .git/hooks/pre-commit
#!/bin/sh
composer docs || exit 1
laravel/api-doc to auto-generate OpenAPI specs from routes.@internal:
/**
* @internal
*/
public function getFullNameAttribute() { ... }
--directory to scope generation to a single package:
vendor/bin/phpdoc -d ./packages/my-package -t ./docs/api
How can I help you explore Laravel packages today?