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.
Use cases: In-repository documentation, GitHub/GitLab wikis, AI prompt context.
Wish there was an easy way to generate PHP source code documentation?
Using phpDocumentor with phpDocumentor-markdown template, you can automatically generate GitHub/GitLab-ready Markdown documentation from PHP source code.
This template can be used to document:
| Name | Descriptions | Inheritance | Implements | Constants | Properties | Methods | Inherited methods | |
|---|---|---|---|---|---|---|---|---|
| Classes | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Interfaces | ✅ | ✅ | ✅ | ➖ | ✅ | ✅ | ✅ | ➖ |
| Traits | ✅ | ✅ | ➖ | ➖ | ✅ | ✅ | ✅ | ➖ |
| Name | Descriptions | Types (parameter, return, etc.) | Access modifiers | |
|---|---|---|---|---|
| Functions | ✅ | ✅ | ✅ | ✅ |
| Methods | ✅ | ✅ | ✅ | ✅ |
| Properties | ✅ | ✅ | ✅ | ✅ |
Examples are available in the .wiki directory.
phpdoc is the phpDocumentor binary.# Run phpDocumentor with --template argument pointed to this directory's markdown template
phpdoc --directory=src --target=docs --template=<PATH TO THIS REPOSITORY/themes/markdown>
# Require this package. You probably want it as a dev dependency
composer require --dev saggre/phpdocumentor-markdown
# Run phpDocumentor with --template argument pointed to markdown template inside vendor directory
phpdoc --directory=src --target=docs --template="vendor/saggre/phpdocumentor-markdown/themes/markdown"
Add this script to your composer.json and run composer create-docs to generate the documentation.
"scripts": {
"create-docs": "phpdoc --directory=src --target=docs --template='vendor/saggre/phpdocumentor-markdown/themes/markdown'"
},
Add a template element to your phpDocumentor XML config and run phpDocumentor to generate the documentation.
<phpdocumentor>
<!-- Specify template element inside phpdocumentor -->
<template name="./vendor/saggre/phpdocumentor-markdown/themes/markdown"/>
</phpdocumentor>
You can also check out the config file used for generating this repository's example documentation for a full example.
The output of this template can be used directly as a GitLab wiki.
⚠️ GitHub wiki uses a flat directory structure for linking, so the internal links in the resulting documentation will not work as expected.
You can use the PhpDocumentor Docker image with this template in your CI pipelines to generate documentation automatically.
The generated documentation can be used as prompt context for AI models that work with source code. For other use cases you'll likely want structured data, like JSON.
# Clone the repository
git clone git@github.com:Saggre/phpDocumentor-markdown.git
# Go to the cloned repository
cd phpDocumentor-markdown
# Install dependencies
composer install
# Set up PHPUnit configuration
cp phpunit.xml.dist phpunit.xml
# Run PHPUnit in project root directory
composer test
tests directory.
How can I help you explore Laravel packages today?