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.
nasirkhan/laravel-sharekit
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