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

daviddel/doctrine-manager-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require daviddel/doctrine-manager-bundle
    

    Enable the bundle in app/AppKernel.php:

    new Doctrine\ManagerBundle\DoctrineManagerBundle(),
    
  2. First Use Case:

    • Define a custom manager for an entity (e.g., Content) by annotating it with @MM\ModelManager.
    • Inject the manager.factory service to fetch the manager instance in controllers/services.

Key Files to Review

  • Resources/config/services.xml (for service configuration).
  • Entity/Manager/ (custom manager classes).
  • Entity/ (annotated entities with @MM\ModelManager).

Implementation Patterns

Workflow: Custom Manager Integration

  1. Define a Manager Class:

    // src/AppBundle/Entity/Manager/ContentManager.php
    namespace AppBundle\Entity\Manager;
    
    use Doctrine\Manager\Model\ORM\Manager;
    
    class ContentManager extends Manager
    {
        public function publish($content)
        {
            // Custom logic (e.g., soft-deletion, event triggers)
            $this->getEntityManager()->flush();
        }
    }
    
  2. Annotate Entity:

    /** @MM\ModelManager(class="AppBundle\Entity\Manager\ContentManager") */
    class Content {}
    
  3. Use in Controller/Service:

    $manager = $this->get('manager.factory')->getManager(Content::class);
    $manager->publish($content); // Calls custom logic
    

Integration Tips

  • Dependency Injection: Prefer constructor injection for managers in services:
    public function __construct(ManagerFactory $managerFactory) {
        $this->managerFactory = $managerFactory;
    }
    
  • Repository Overrides: Extend EntityRepository in @ORM\Entity to add custom methods:
    /** @ORM\Entity(repositoryClass="AppBundle\Entity\Repository\ContentRepository") */
    
  • Event Listeners: Attach listeners to managers for pre/post operations:
    $manager->getEntityManager()->getEventManager()->addEventListener(...);
    

Gotchas and Tips

Pitfalls

  1. Outdated Package:

    • Last release in 2016 may cause compatibility issues with modern Laravel (8+/9+) or Doctrine ORM 2.10+.
    • Workaround: Fork the repo and update dependencies (e.g., doctrine/doctrine-manager-bundle).
  2. Service Registration:

    • Ensure manager.factory is properly registered in services.xml or config/services.yaml.
    • Debug Tip: Check bin/console debug:container manager.factory to verify service availability.
  3. Annotation Conflicts:

    • @MM\ModelManager must precede @ORM\Entity in class docblocks to avoid parsing errors.
  4. Circular Dependencies:

    • Avoid injecting managers into other managers to prevent circular references.

Debugging

  • Manager Not Found:

    • Verify the manager class path in @MM\ModelManager matches the actual file location.
    • Check for typos in the factory call:
      $manager = $this->get('manager.factory')->getManager(Content::class);
      
  • ORM Exceptions:

    • Use var_dump($manager->getEntityManager()) to confirm the underlying ORM instance is valid.

Extension Points

  1. Custom Manager Methods:

    • Extend Doctrine\Manager\Model\ORM\Manager to add domain-specific logic (e.g., bulk operations).
  2. Dynamic Manager Resolution:

    • Override Doctrine\ManagerBundle\ManagerFactory to implement custom resolution logic (e.g., based on user roles).
  3. Hybrid ORM/ODM:

    • Combine with Doctrine\ODM by extending Doctrine\Manager\Model\ODM\Manager (if supported by the package).
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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle