Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Doctrine Annotation Autoload Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. 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"
        ]
    }
    
  2. Configuration Ensure your composer.json includes Doctrine annotations in the autoload section:

    "autoload": {
        "psr-4": {
            "App\\": "src/"
        },
        "classmap": ["vendor/doctrine/annotations/lib"]
    }
    
  3. 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.


Implementation Patterns

Workflows

  1. 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 { ... }
    
  2. 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,
                ],
            ],
        ],
    ];
    
  3. Laravel-Specific Usage

    • Service Providers: Register Doctrine ORM in 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);
      }
      
    • Annotations in Controllers:
      use Doctrine\ORM\Mapping as ORM;
      
      /** @ORM\Entity */
      class UserController extends Controller { ... }
      
  4. Testing Mock annotations in tests by regenerating the autoloader:

    composer dump-autoload --optimize
    

Gotchas and Tips

Pitfalls

  1. Archived Package

    • No active maintenance; consider alternatives like doctrine/annotations + custom Composer scripts.
    • Risk of compatibility issues with newer PHP/Composer versions.
  2. Annotation Parsing Conflicts

    • If annotations are ignored, verify:
      • The classmap for doctrine/annotations is included in composer.json.
      • No typos in annotation syntax (e.g., @ORM\Entity vs @Entity).
    • Debug with:
      composer dump-autoload --verbose
      
  3. Caching Issues

    • Clear Composer cache if annotations stop working:
      composer clear-cache
      
    • Ensure vendor/ is not excluded from autoload generation.
  4. Laravel-Specific Quirks

    • Class Loading Order: Laravel’s autoloader may override Doctrine’s. Use composer dump-autoload after php artisan optimize.
    • Namespace Conflicts: Avoid naming classes to conflict with Doctrine’s internal classes (e.g., Annotation).

Tips

  1. 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"
        ]
    }
    
  2. Performance

    • Use --optimize for production:
      composer dump-autoload --optimize
      
    • Exclude vendor/ from Git to reduce bloat.
  3. Alternatives

    • For modern Laravel, prefer:
      composer require doctrine/annotations
      
      Then manually configure Doctrine ORM to use the annotation reader.
  4. Debugging

    • Check generated vendor/composer/autoload_classmap.php for missing annotations.
    • Use var_dump(class_exists('Doctrine\Common\Annotations\AnnotationReader')) to verify setup.
  5. Legacy Codebases

    • If migrating from Symfony, this package may reduce boilerplate for Doctrine integration. Document its archived status in README.md.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle