2017 © Pedro Peláez
 

library repo-service-bundle

Declare Doctrine repository as a Symfony service

image

davidkmenta/repo-service-bundle

Declare Doctrine repository as a Symfony service

  • Monday, October 3, 2016
  • by david.kmenta
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

RepoServiceBundle

FOR EXPERIMENTAL USE ONLY!, (*1)

The RepoServiceBundle provides the ability to declare a Doctrine repositories as a Symfony services., (*2)

Requirements

  • Symfony >= 3
  • Doctrine >= 2.5
  • PHP >= 5.6

Installation

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(),
        // ...
    ];
}

Documentation

  • Note: This bundle overrides the doctrine.orm.entity_manager.class option and setups an own entity manager.
  • First of all, you have to create or update your repository class. A repository class has to extend the class DavidKmenta\RepoServiceBundle\Repository\EntityRepository.
  • Now you have to implement a method 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;
    }
}
  • Last step is about defining the repository as a service. It's as simple as any other definition:
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)

TODOs and known issues

  • Instead of using the method getMappedEntityName, declare an entity name through a class annotation.
  • A custom entity manager isn't supported.

Disclaimer

Using this bundle is on own risk., (*6)

License

MIT, (*7)

Contributing

Any contribution is welcomed :-), (*8)

The Versions

03/10 2016

dev-master

9999999-dev

Declare Doctrine repository as a Symfony service

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Kmenta