phpdocumentor/shim
Composer shim to install phpDocumentor as a PHAR. Downloads the official release PHAR from the main phpDocumentor repo and places it in vendor/bin for easy use in your project. Use main repo for bleeding-edge versions and issue tracking.
Installation: Add the package to your Laravel project via Composer:
composer require --dev phpdocumentor/shim:^3
This installs the phpdocumentor.phar into vendor/bin/ as phpdocumentor.
First Use Case: Generate basic PHPDoc documentation for your Laravel project:
vendor/bin/phpdocumentor run -d src --target docs
-d src: Specifies the source directory (Laravel’s app/ or src/).--target docs: Outputs documentation to a docs/ directory.Where to Look First:
app/ or src/ directories, excluding vendor/, node_modules/, and generated files..github/workflows/ or gitlab-ci.yml for automated documentation.Basic Documentation Generation:
vendor/bin/phpdocumentor run -d app/Http/Controllers -t docs/api
Template Customization:
Configure phpdocumentor.dist.php in your project root:
return [
'source' => ['app'],
'target' => 'docs',
'template' => 'vendor/phpdocumentor/templates-twbsbootstrap',
'cache' => 'var/cache',
'parser' => [
'full_fqcn' => true,
'filter' => ['@ignore'],
],
];
twbsbootstrap for Bootstrap-styled docs).@ignore annotations.CI/CD Integration:
Add to composer.json scripts for easy execution:
"scripts": {
"post-install-cmd": [
"@phpdoc-install"
],
"phpdoc-install": "php vendor/bin/phpdocumentor/install"
}
Run in GitHub Actions:
- name: Generate Documentation
run: vendor/bin/phpdocumentor run --processes=2
Artisan Command Integration (Advanced):
Create a custom Artisan command to wrap phpdocumentor:
// app/Console/Commands/GenerateDocs.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
class GenerateDocs extends Command
{
protected $signature = 'docs:generate {--target=docs}';
protected $description = 'Generate PHPDoc documentation';
public function handle()
{
$process = new Process(['vendor/bin/phpdocumentor', 'run', '-d', 'app', '--target=' . $this->option('target')]);
$process->run();
$this->output->write($process->getOutput());
}
}
Register in app/Console/Kernel.php:
protected $commands = [
Commands\GenerateDocs::class,
];
Run with:
php artisan docs:generate --target=docs/custom
Parallel Processing: Speed up generation in CI/CD with multiple processes:
vendor/bin/phpdocumentor run --processes=4
Developer Workflow:
vendor/bin/phpdocumentor run -d app -t docs/dev
Release Workflow:
main branch pushes:
# .github/workflows/docs.yml
name: Documentation
on: [push]
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-php@v2
with:
php-version: '8.2'
- run: composer install --dev
- run: vendor/bin/phpdocumentor run --processes=2
docs/ to a static host (e.g., GitHub Pages, Netlify).Open-Source Workflow:
README.md:
## Documentation
[View API Docs](docs/index.html)
phpdocumentor to generate OpenAPI specs for API-first projects.Exclude Files:
Use .phpdoc.dist.php to ignore tests, configs, or generated files:
return [
'filter' => [
'exclude' => [
'tests/*',
'config/*',
'storage/*',
],
],
];
Custom Annotations:
Extend PHPDoc with custom tags (e.g., @see, @method) and configure parsing:
'parser' => [
'customTags' => ['see', 'method'],
],
Laravel-Specific:
vendor/bin/phpdocumentor run -d app/Providers app/Facades -t docs/framework
@mixin for trait documentation.Versioning: Tag releases with docs:
git tag v1.0.0
vendor/bin/phpdocumentor run --target=docs/v1.0.0
PHP Version Mismatch:
phpdocumentor/shim@^3 requires PHP 8.1+. Laravel <8.33 (PHP 8.0) or <9.x (PHP 7.4) will fail.phpdocumentor/shim@^3.9 for PHP 8.0 support or upgrade Laravel.Template Path Changes:
templates/twbsbootstrap no longer work. Use PSR-12 paths:
'template' => 'vendor/phpdocumentor/templates-twbsbootstrap',
phpdocumentor.dist.php and clear cache (rm -rf var/cache).Deprecated APIs:
\phpDocumentor\Transformer or event listeners will break.phpDocumentor\Processor:
// Old
$transformer = new \phpDocumentor\Transformer\DefaultTransformer();
// New
$processor = new \phpDocumentor\Processor();
$processor->process($sourceFiles);
Composer Conflicts:
phpdocumentor/shim and phpdocumentor/phpdocumentor may cause conflicts.phpdocumentor/phpdocumentor dependency and rely on the shim.Parallel Processing Issues:
--processes flag may fail on shared CI runners with low memory.--processes=2 and monitor resource usage.Annotation Parsing Quirks:
@api) may not render correctly.'parser' => [
'customTags' => ['api', 'deprecated'],
],
Cache Invalidation:
rm -rf var/cache
vendor/bin/phpdocumentor run
Verbose Output: Enable debug mode for troubleshooting:
vendor/bin/phpdocumentor run -vvv
Dry Run: Test configuration without generating files:
vendor/bin/phpdocumentor run --dry-run
Log File: Redirect output to a log file:
vendor/bin/phpdocumentor run > docs/generation.log 2>&1
Default Config Location:
phpdocumentor.dist.php in the project root or vendor/phpdocumentor/.--configuration:
vendor/bin/phpdocumentor run --configuration=custom.phpdoc.php
Template Overrides:
templates/ and modify:
cp -r vendor/phpdocumentor/templates-twbsbootstrap templates/custom
'template' => 'templates/custom',
Parallel Processing Limits:
vendor/bin/phpdocumentor run --process
How can I help you explore Laravel packages today?