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

arturdoruch/doctrine-entity-manager-bundle

View on GitHub
Deep Wiki
Context7

DoctrineEntityManagerBundle

Symfony Bundle helping to create and access to the own Doctrine entity manager classes (with operations doing on the entity).

Installation

composer require arturdoruch/doctrine-entity-manager-bundle

Register bundle in kernel class.

$bundles = [
    new ArturDoruch\DoctrineEntityManagerBundle\ArturDoruchDoctrineEntityManagerBundle(),
];

Usage

Creating entity manager

In order to creating Doctrine entity manager class extend the ArturDoruch\DoctrineEntityManagerBundle\AbstractEntityManager abstract class, and implement required getRepository() method returning the repository class of managing entity.

Example:

<?php

namespace AppBundle\Doctrine;

use AppBundle\Entity\Foo;
use ArturDoruch\DoctrineEntityManagerBundle\AbstractEntityManager;

class FooManager extends AbstractEntityManager
{
    public function getRepository()
    {
        return $this->doGetRepository(Foo::class);
    }
    
    // Custom entity manager methods.
    
    /*public function create(): Foo
    {
        $foo = new Foo();
        
        return $foo;
    }
        
    
    public function save(Foo $foo)
    {
        $this->persist($foo);
    }
    
    
    public function remove(Foo $foo)
    {
        $this->doRemove($foo);
    }*/
}

Register entity manager as service

To register entity manager as service, add the arturdoruch.doctrine_entity_manager tag to the service configuration.

doctrine.foo_manager:
    class: AppBundle\Doctrine\FooManager
    tags: ['arturdoruch.doctrine_entity_manager']

Accessing entity managers

All managers are registered in ArturDoruch\DoctrineEntityManagerBundle\EntityManagerRegistry class. To get specific entity manager pass it class name to the get() method.

In controller:

<?php

$emr = $this->get('arturdoruch.doctrine_entity_manager_registry');
$fooManager = $emr->get(FooManager::class);
$barManager = $emr->get(BarManager::class);

In entity manager:

<?php

namespace AppBundle\Doctrine;

use AppBundle\Entity\Foo;
use AppBundle\Doctrine\BarManager;
use ArturDoruch\DoctrineEntityManagerBundle\AbstractEntityManager;

class FooManager extends AbstractEntityManager
{
    /**
     * @var BarManager
     */
    private $barManager;
    
    public function initialize()
    {
        $this->barManager = $this->getManager(BarManager::class);
    }
}

Class API

ArturDoruch\DoctrineEntityManagerBundle\AbstractEntityManager

Protected methods for use in the entity manager class:

  • getEntityManagerName
  • initialize
  • getManager
  • persist
  • doRemove
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