dev-master
9999999-devDeclare Doctrine repository as a Symfony service
MIT
The Requires
- php >=5.6
- symfony/symfony 3.*
- doctrine/orm ^2.5
The Development Requires
by David Kmenta
Wallogit.com
2017 © Pedro Peláez
Declare Doctrine repository as a Symfony service
FOR EXPERIMENTAL USE ONLY!, (*1)
The RepoServiceBundle provides the ability to declare a Doctrine repositories as a Symfony services., (*2)
Require the bundle with the composer:, (*3)
composer require davidkmenta/repo-service-bundle "dev-master"
Enable the bundle in the kernel:, (*4)
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = [
// ...
new DavidKmenta\RepoServiceBundle\RepoServiceBundle(),
// ...
];
}
doctrine.orm.entity_manager.class option and setups an own entity manager.DavidKmenta\RepoServiceBundle\Repository\EntityRepository.getMappedEntityName which tells to the EntityManager what entity is managed by this repository. The best practise is, return a fully qualified class name:<?php
namespace AcmeBundle\Repository;
use AcmeBundle\Entity\CustomEntity;
use DavidKmenta\RepoServiceBundle\Repository\EntityRepository;
use Psr\Log\LoggerInterface;
class CustomRepository extends EntityRepository
{
public function __construct(LoggerInterface $logger)
{
// ...
}
public function getMappedEntityName()
{
return CustomEntity::class;
}
}
acme.repository.custom:
class: AcmeBundle\Repository\CustomRepository
arguments: ["@logger"]
tags:
- { name: doctrine.repository }
That's it! Yes, the trick is in the tag doctrine.repository :-) and the logger is injected as you're expecting., (*5)
getMappedEntityName, declare an entity name through a class annotation.Using this bundle is on own risk., (*6)
MIT, (*7)
Any contribution is welcomed :-), (*8)
Declare Doctrine repository as a Symfony service
MIT