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.
- PHP >= 7.0
- Symfony >= 2.7
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(),
// ...
];
}
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);