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 Bundle Laravel Package

dontdrinkandroot/doctrine-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require dontdrinkandroot/doctrine-bundle
    

    Add the bundle to config/bundles.php in a Symfony/Laravel-Symfony hybrid project:

    return [
        // ...
        Dontdrinkandroot\DoctrineBundle\DontdrinkandrootDoctrineBundle::class => ['all' => true],
    ];
    
  2. Configuration: Override default settings in config/packages/dontdrinkandroot_doctrine.yaml (if using Symfony) or manually configure in Laravel's service container.

  3. First Use Case: Use the DoctrineExtensions service to enable behaviors like:

    // Example: Enable Sluggable behavior for an entity
    use Gedmo\Sluggable\SluggableListener;
    
    $entityManager->getEventManager()->addEventSubscriber(new SluggableListener());
    

Implementation Patterns

Common Workflows

  1. Entity Listeners/Subscribers: Register Doctrine event listeners (e.g., Sluggable, Timestampable) via the bundle’s configuration:

    # config/packages/dontdrinkandroot_doctrine.yaml
    doctrine:
        orm:
            listeners:
                gedmo_sluggable: true
                gedmo_timestampable: true
    
  2. Custom Extensions: Extend existing behaviors (e.g., add a SoftDeleteable trait) by:

    • Creating a custom listener.
    • Registering it in services.yaml:
      services:
          App\EventListener\CustomSoftDeleteListener:
              tags:
                  - { name: 'doctrine.event_subscriber', connection: 'default' }
      
  3. Laravel Integration: Use the bundle’s services in Laravel via Symfony’s HttpKernel (if hybrid) or manually bind Doctrine components:

    // config/app.php (Laravel)
    'providers' => [
        // ...
        Dontdrinkandroot\DoctrineBundle\ServiceProvider::class,
    ],
    
  4. Query Utilities: Leverage the bundle’s query helpers (e.g., TreeType, Sortable) in repositories:

    $qb = $entityManager->createQueryBuilder();
    $qb->select('e')
       ->from('App\Entity\Post', 'e')
       ->add('orderBy', 'e.position ASC');
    

Gotchas and Tips

Pitfalls

  1. Outdated Dependencies:

    • The package relies on Doctrine ORM 2.5+ and Gedmo behaviors (e.g., Sluggable). Ensure compatibility:
      composer require gedmo/doctrine-extensions
      
    • Symfony 4+: The bundle may require manual adjustments (e.g., config/bundles.php vs. AppKernel).
  2. Laravel-Specific Issues:

    • No Native Laravel Support: The bundle is Symfony-first. Use a bridge like symfony/doctrine-bridge or manually integrate Doctrine services.
    • Service Container Conflicts: Override the bundle’s services in Laravel’s AppServiceProvider:
      public function register()
      {
          $this->app->bind('doctrine', function ($app) {
              return new \Doctrine\ORM\EntityManager($app['doctrine.connection']);
          });
      }
      
  3. Configuration Overrides:

    • The bundle may not auto-register listeners. Explicitly add them in bootstrap/app.php (Laravel) or config/packages/doctrine.yaml (Symfony):
      // Laravel: Manually register listeners
      $entityManager->getEventManager()->addEventSubscriber(new \Gedmo\Sluggable\SluggableListener());
      

Debugging Tips

  1. Event Subscriber Debugging:

    • Check if listeners are registered:
      $subscribers = $entityManager->getEventManager()->getListeners();
      dump(array_keys($subscribers)); // Look for 'prePersist', 'preUpdate', etc.
      
    • Enable Doctrine debug mode in .env:
      DOCTRINE_ORM_DEBUG=true
      
  2. Query Logging:

    • Enable SQL logging for complex queries:
      $entityManager->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
      

Extension Points

  1. Custom Behaviors:

    • Create a new behavior (e.g., Versionable) by extending Gedmo\AbstractBehavior and register it via the bundle’s configuration.
  2. Lifecycle Callbacks:

    • Use the bundle’s event system to trigger actions (e.g., send email on postPersist):
      // In a custom subscriber
      public function postPersist(LifecycleEventArgs $args)
      {
          $entity = $args->getObject();
          if ($entity instanceof Post) {
              // Send email logic
          }
      }
      
  3. Hybrid Projects:

    • For Laravel-Symfony projects, use the bundle’s services via Symfony’s HttpKernel:
      $kernel = new AppKernel('prod', false);
      $kernel->boot();
      $container = $kernel->getContainer();
      $doctrine = $container->get('doctrine');
      
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.
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
spatie/mailcoach-vapor