indigophp/doctrine-annotation-autoload
Laravel-friendly autoloading for Doctrine annotations. Automatically registers annotation classes so you can use Doctrine-style annotations without manual loader setup, reducing boilerplate and avoiding common “annotation not found” errors in PHP projects.
Installation Add the package via Composer (though note its archived status):
composer require indigophp/doctrine-annotation-autoload
Register the autoloader plugin in composer.json:
"scripts": {
"post-autoload-dump": [
"DoctrineAnnotationAutoload\\Composer\\ScriptHandler::postAutoloadDump"
]
}
Configuration
Ensure your composer.json includes Doctrine annotations in the autoload section:
"autoload": {
"psr-4": {
"App\\": "src/"
},
"classmap": ["vendor/doctrine/annotations/lib"]
}
First Use Case
Run composer dump-autoload to generate the autoloader. Now Doctrine annotations (e.g., @ORM\Entity) will be recognized without manual classmap configuration.
Annotation-Driven Development
Use annotations (e.g., @Route, @Entity) directly in PHP classes without extra configuration:
use Doctrine\ORM\Mapping as ORM;
/** @ORM\Entity */
class User { ... }
Integration with Doctrine ORM
Combine with doctrine/orm for seamless entity mapping:
composer require doctrine/orm
Configure doctrine/annotations in config/autoload.php:
return [
'doctrine' => [
'orm' => [
'annotations' => [
'autoload_metadata' => true,
],
],
],
];
Laravel-Specific Usage
AppServiceProvider:
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
public function boot()
{
$paths = [__DIR__.'/../src'];
$isDevMode = true;
$proxyDir = null;
$cache = null;
$useSimpleAnnotationReader = false;
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, $proxyDir, $cache, $useSimpleAnnotationReader);
$entityManager = EntityManager::create(['url' => 'sqlite:///:memory:'], $config);
}
use Doctrine\ORM\Mapping as ORM;
/** @ORM\Entity */
class UserController extends Controller { ... }
Testing Mock annotations in tests by regenerating the autoloader:
composer dump-autoload --optimize
Archived Package
doctrine/annotations + custom Composer scripts.Annotation Parsing Conflicts
classmap for doctrine/annotations is included in composer.json.@ORM\Entity vs @Entity).composer dump-autoload --verbose
Caching Issues
composer clear-cache
vendor/ is not excluded from autoload generation.Laravel-Specific Quirks
composer dump-autoload after php artisan optimize.Annotation).Custom Annotation Directories
Extend the package’s behavior by modifying the postAutoloadDump script in composer.json:
"scripts": {
"post-autoload-dump": [
"DoctrineAnnotationAutoload\\Composer\\ScriptHandler::postAutoloadDump",
"@php artisan optimize"
]
}
Performance
--optimize for production:
composer dump-autoload --optimize
vendor/ from Git to reduce bloat.Alternatives
composer require doctrine/annotations
Then manually configure Doctrine ORM to use the annotation reader.Debugging
vendor/composer/autoload_classmap.php for missing annotations.var_dump(class_exists('Doctrine\Common\Annotations\AnnotationReader')) to verify setup.Legacy Codebases
README.md.How can I help you explore Laravel packages today?