lendable/doctrine-extensions-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Provides extensions to how Doctrine is integrated with Symfony like enabling repositories to have extra constructor arguments and behind the scenes retrieval/instantiation via the container.

Installs: 12 943

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 25

Forks: 0

Open Issues: 1

Type:symfony-bundle

v1.0.3 2017-11-17 16:09 UTC

This package is auto-updated.

Last update: 2023-09-02 11:03:10 UTC


README

Build Status Coverage Status Total Downloads Scrutinizer Code Quality

Licensed under the MIT License.

Provides extensions to how Doctrine is integrated with Symfony. This includes:

  • Allowing repositories to have extra constructor arguments and behind the scenes retrieval / instantiation via the container.

Requirements

  • PHP >= 7.0
  • Symfony >= 2.7

Installation

Require the bundle with Composer:

composer require lendable/doctrine-extensions-bundle

Enable the bundle:

<?php
// app/AppKernel.php

public function registerBundles() 
{
    $bundles = [
      // ...
      new Lendable\DoctrineExtensionsBundle\LendableDoctrineExtensionsBundle(),        
      // ...        
    ];
}

Usage

Repositories with dependencies

A repository with extra constructor arguments such as:

<?php
// src/App/Entity/Repository/ExampleRepository.php

namespace App\Entity\Repository;

class ExampleRepository extends EntityRepository
{
    public function __construct(
        EntityManager $entityManager, 
        ClassMetadata $classMetadata,
        string $customRawValue,
        string $customParameter, 
        CustomService $customService,
        array $customArray) 
    {
        parent::__construct($entityManager, $classMetadata);
        
        $this->customRawValue = $customRawValue;
        $this->customParameter = $customParameter;
        $this->customService = $customService;
        $this->customArray = $customArray;
    }
}

Should be configured to inform the bundle how these extra dependencies should be sourced.

lendable_doctrine_extensions:
    repositories:
        App\Entity\Repository\ExampleRepository:
            entity: App\Entity\Example
            managers: ['default', 'custom_manager']
            args:
                - 'a literal raw value'
                - '%custom_parameter%'
                - '@custom_service'
                - 
                    config: '@config_service'
                    raw_value: 'a literal raw value'

An argument can either be:

  • Raw scalar.
  • Parameter reference (%wrapped%).
  • Service reference (@prefixed).
  • An indexed/associative array of any of the above.

The repository can now be retrieved as usual via the Doctrine Registry or EntityManager.

<?php

// Via the registry...

$repository = $container->get('doctrine')->getRepository(App\Entity\Example::class);

// Via the entity manager...

$repository = $container->get('doctrine')->getManager()->getRepository(App\Entity\Example::class);