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

Symfony Bundle Doctrine Laravel Package

binsoul/symfony-bundle-doctrine

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require binsoul/symfony-bundle-doctrine
    

    Ensure your project uses Symfony 5.4+ (Laravel 8+ via Symfony bridge) or a standalone Symfony app.

  2. Register the Bundle Add to config/bundles.php (Symfony) or config/app.php (Laravel):

    return [
        // ...
        Binsoul\DoctrineBundle\DoctrineBundle::class => ['all' => true],
    ];
    
  3. First Use Case: Basic Doctrine Integration Inject the Doctrine\ORM\EntityManagerInterface into a service/controller:

    use Doctrine\ORM\EntityManagerInterface;
    
    class UserController extends AbstractController
    {
        public function __construct(private EntityManagerInterface $em) {}
    
        public function index()
        {
            $users = $em->getRepository(User::class)->findAll();
            // ...
        }
    }
    
  4. Verify Configuration Check config/packages/doctrine.yaml (auto-generated by the bundle) for DBAL/ORM settings.


Implementation Patterns

Workflows

  1. Repository Pattern Extend Doctrine\ORM\EntityRepository for custom queries:

    namespace App\Repository;
    
    use Doctrine\ORM\EntityRepository;
    
    class UserRepository extends EntityRepository
    {
        public function findActiveUsers()
        {
            return $this->createQueryBuilder('u')
                ->where('u.isActive = :active')
                ->setParameter('active', true)
                ->getQuery()
                ->getResult();
        }
    }
    
  2. Dependency Injection Bind repositories/services in services.yaml:

    services:
        App\Repository\UserRepository:
            arguments:
                $entityManager: '@doctrine.orm.entity_manager'
    
  3. Lifecycle Callbacks Use annotations in entities (e.g., @ORM\PrePersist):

    use Doctrine\ORM\Mapping as ORM;
    
    #[ORM\Entity]
    class User
    {
        #[ORM\PrePersist]
        public function setCreatedAt(): void
        {
            $this->createdAt = new \DateTime();
        }
    }
    
  4. Migrations Generate migrations via:

    php bin/console doctrine:migrations:diff
    php bin/console doctrine:migrations:migrate
    

Integration Tips

  • Laravel-Symfony Bridge: Use symfony/ux-live-component or symfony/var-dumper for debugging.
  • Event Listeners: Register via doctrine.event_dispatcher:
    doctrine.event_dispatcher:
        listeners:
            App\EventListener\UserListener: ~
    
  • QueryBuilder: Prefer createQueryBuilder() over DQL for dynamic queries.

Gotchas and Tips

Pitfalls

  1. Entity Manager Scope

    • The bundle provides one global EntityManager. Avoid injecting multiple instances.
    • Debug with:
      $this->em->getConnection()->getDatabasePlatform()->getName();
      
  2. Configuration Overrides

    • The bundle auto-generates doctrine.yaml. Manual edits may be overwritten.
    • Use doctrine.yaml in config/packages/override/ for customizations.
  3. Laravel Eloquent Conflicts

    • Avoid mixing Eloquent and Doctrine ORM in the same project (use Doctrine exclusively).
  4. Transaction Management

    • Wrap operations in transactions:
      $this->em->beginTransaction();
      try {
          $this->em->persist($entity);
          $this->em->flush();
          $this->em->commit();
      } catch (\Exception $e) {
          $this->em->rollBack();
          throw $e;
      }
      

Debugging

  • Dump Queries:
    $this->em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
    
  • Check Entities:
    php bin/console doctrine:schema:validate
    

Extension Points

  1. Custom DQL Functions Register in doctrine.yaml:

    dbal:
        dql:
            string_functions:
                CONCAT_WS: DoctrineExtensions\Query\Mysql\StringFunctions\ConcatWs
    
  2. Event Subscribers Implement Doctrine\Common\EventSubscriber:

    class SoftDeleteSubscriber implements EventSubscriber
    {
        public function getSubscribedEvents()
        {
            return ['preRemove'];
        }
    
        public function preRemove(LifecycleEventArgs $args)
        {
            $entity = $args->getEntity();
            if ($entity instanceof SoftDeletable) {
                $entity->markAsDeleted();
            }
        }
    }
    
  3. Custom Types Extend Doctrine\DBAL\Types\Type and register:

    orm:
        mappings:
            App:
                type: attribute
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App
                is_bundle: false
    
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.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime