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 Reverse Engineering Laravel Package

bonusone/doctrine-reverse-engineering

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require bonusone/doctrine-reverse-engineering
    

    The package auto-registers via Symfony’s symfony.bundle.

  2. First Run: Generate entities/repositories for your default database connection:

    php bin/console doctrine:reverse-engineering:generate
    

    Outputs to src/Entity and src/Repository by default (configurable).

  3. Verify: Check generated files in src/Entity/ (e.g., User.php) and src/Repository/ (e.g., UserRepository.php).

First Use Case

Legacy DB Migration:

  • Point DATABASE_URL to your existing database.
  • Run the command to scaffold entities/repositories.
  • Use generated entities in Symfony forms, controllers, or services (e.g., UserRepository::findAll()).

Implementation Patterns

Workflows

  1. Incremental Generation:

    • Use --connection to target specific databases (e.g., --connection=legacy_db).
    • Regenerate only modified tables by deleting existing files first (or set overwrite_existing: true cautiously).
  2. Custom Namespace/Path: Override defaults in config/packages/doctrine_reverse_engineering.yaml:

    doctrine_reverse_engineering:
        entity_namespace: 'App\Domain\User\Entity'
        repository_path: '%kernel.project_dir%/src/Domain/User/Repository'
    
  3. CI/CD Integration: Add to deployment scripts to auto-generate entities on schema changes:

    php bin/console doctrine:reverse-engineering:generate --overwrite
    

Integration Tips

  • Doctrine Fixtures: Use generated entities with doctrine:fixtures:load for test data. Example: UserFixtures::load() referencing User entity.

  • Symfony Maker: Extend generated entities with custom logic (e.g., add #[ORM\GeneratedValue] or traits).

  • API Platform: Annotate entities with @ApiResource for auto-generated API endpoints:

    #[ApiResource]
    class User { ... }
    
  • Event Subscribers: Hook into postGenerate events (if extended) to auto-register services or seed data.


Gotchas and Tips

Pitfalls

  1. Overwriting Files:

    • Default overwrite_existing: false prevents accidents but may require manual cleanup.
    • Fix: Use --overwrite flag sparingly or set overwrite_existing: true in config.
  2. Namespace Collisions:

    • Generated namespaces default to App\Entity. Conflicts arise if multiple bundles use the same namespace.
    • Fix: Customize entity_namespace per bundle (e.g., App\Bundle\Admin\Entity).
  3. Complex Schema Quirks:

    • JSON/ARRAY columns may generate incomplete type hints (e.g., ?array instead of JsonEncoded).
    • Fix: Post-process files or extend the generator (see "Extension Points").
  4. Doctrine Migrations:

    • Generated entities may not align with pending migrations.
    • Fix: Run doctrine:migrations:diff after generation to sync schema.

Debugging

  • Dry Run: Use --dry-run (if available) or check var/log/dev.log for connection errors. Example error:

    [Doctrine\DBAL\Exception\ConnectionException] An exception occurred while executing 'SELECT ...': SQLSTATE[HY000] [2002] No such file or directory
    

    Fix: Verify DATABASE_URL (e.g., mysql://user:pass@localhost/db).

  • Generated Code Issues:

    • Invalid PHP syntax (e.g., missing use statements) often stems from malformed DB schema.
    • Fix: Validate SQL first with doctrine:schema:validate.

Tips

  1. Partial Generation: Target specific tables by filtering in the generator (if supported) or manually edit the command’s logic.

  2. Extension Points:

    • Override the generator by extending BonusOne\DoctrineReverseEngineering\Generator\Generator and binding it in services.yaml:
      BonusOne\DoctrineReverseEngineering\Generator\Generator: '@app.custom_generator'
      
  3. Template Customization: Modify the Twig templates (located in the package’s Resources/views/) to change entity/repo structure (e.g., add #[ORM\Table(name: 'custom_name')]).

  4. Performance: For large databases, generate entities in batches or during off-peak hours.

  5. Testing: Use the generator in a phpunit.xml setup to scaffold test entities:

    php bin/console doctrine:reverse-engineering:generate --entity-namespace="App\Tests\Entity"
    
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky