daviddel/doctrine-manager-bundle
Installation:
composer require daviddel/doctrine-manager-bundle
Enable the bundle in app/AppKernel.php:
new Doctrine\ManagerBundle\DoctrineManagerBundle(),
First Use Case:
Content) by annotating it with @MM\ModelManager.manager.factory service to fetch the manager instance in controllers/services.Resources/config/services.xml (for service configuration).Entity/Manager/ (custom manager classes).Entity/ (annotated entities with @MM\ModelManager).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();
}
}
Annotate Entity:
/** @MM\ModelManager(class="AppBundle\Entity\Manager\ContentManager") */
class Content {}
Use in Controller/Service:
$manager = $this->get('manager.factory')->getManager(Content::class);
$manager->publish($content); // Calls custom logic
public function __construct(ManagerFactory $managerFactory) {
$this->managerFactory = $managerFactory;
}
EntityRepository in @ORM\Entity to add custom methods:
/** @ORM\Entity(repositoryClass="AppBundle\Entity\Repository\ContentRepository") */
$manager->getEntityManager()->getEventManager()->addEventListener(...);
Outdated Package:
doctrine/doctrine-manager-bundle).Service Registration:
manager.factory is properly registered in services.xml or config/services.yaml.bin/console debug:container manager.factory to verify service availability.Annotation Conflicts:
@MM\ModelManager must precede @ORM\Entity in class docblocks to avoid parsing errors.Circular Dependencies:
Manager Not Found:
@MM\ModelManager matches the actual file location.$manager = $this->get('manager.factory')->getManager(Content::class);
ORM Exceptions:
var_dump($manager->getEntityManager()) to confirm the underlying ORM instance is valid.Custom Manager Methods:
Doctrine\Manager\Model\ORM\Manager to add domain-specific logic (e.g., bulk operations).Dynamic Manager Resolution:
Doctrine\ManagerBundle\ManagerFactory to implement custom resolution logic (e.g., based on user roles).Hybrid ORM/ODM:
Doctrine\ODM by extending Doctrine\Manager\Model\ODM\Manager (if supported by the package).How can I help you explore Laravel packages today?