2017 © Pedro Peláez
 

library doctrine-extended-repository-bundle

Allows the use of DI within Doctrine Repositories

image

wms/doctrine-extended-repository-bundle

Allows the use of DI within Doctrine Repositories

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 4 % Grown

The README.md

WMSDoctrineExtendedRepositoriesBundle

The WMSDoctrineExtendedRepositoriesBundle allows you to use dependency injection within Doctrine Repositories by registering them as services., (*1)

This document contains information on how to download, install and use this bundle., (*2)

1) Installing the Bundle

Using Composer

As Symfony uses [Composer][1] to manage its dependencies, the recommended way to install this bundle is to use it., (*3)

If you don't have Composer yet, download it following the instructions on [http://getcomposer.org/][1] or just run the following command:, (*4)

curl -s http://getcomposer.org/installer | php

Then, use the require command to download this bundle:, (*5)

php composer.phar require wms/doctrine-extended-repository-bundle:~1.0@dev

Finally, edit your AppKernel.php file and add the bundle:, (*6)

WMS\Bundle\DoctrineExtendedRepositoriesBundle\WMSDoctrineExtendedRepositoriesBundle()

2) Usage

In order to create a repository, simply create a new class using the following template:, (*7)

use Doctrine\ORM;

class MyCustomRepository extends EntityRepository {
    private $dep;

    /**
     * Initializes a new EntityRepository.
     *
     * @param EntityManager         $em    The EntityManager to use.
     * @param Mapping\ClassMetadata $class The class descriptor.
     * @param MyDependency          $dep   The rest of the arguments are yours to choose!
     */
    public function __construct($em, Mapping\ClassMetadata $class, MyDependency $dep) {
        parent::__construct($em, $class);

        $this->dep = $dep;
    }
}

IMPORTANT: In order to be compatible with Doctrine repositories, the first two arguments of your repository are reserved to the entity manager and the ClassMetadata of your entity. These will be automatically injected., (*8)

Then, simply define your service:, (*9)

**XML: **, (*10)


<container xmlns="http://symfony.com/schema/dic/services"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>
        <service id="my_super_repository" class="MyCustomRepository">
            <argument type="service" id="my_dependency" />
            <tag name="wms.doctrine_extended_repository" entity="ACMEBundle:SuperEntity" connection="default" />
        </service>
    </services>
</container>

**YAML: **, (*11)

services:
    my_super_repository:
        class: MyCustomRepository
        arguments: [ @my_dependency ]
        tags:
            - { name: wms.doctrine_extended_repository, entity: "ACMEBundle:SuperEntity", connection: default }

You may omit the connection attribute on the tag. If so, it will use the default connection/entity manager., (*12)

The WMS Doctrine Extended Repository Bundle is released under the MIT license., (*13)

Enjoy!, (*14)

The Versions

08/05 2014

dev-master

9999999-dev

Allows the use of DI within Doctrine Repositories

  Sources   Download

MIT

The Requires

 

The Development Requires