lendable/doctrine-extensions-bundle

此包已被放弃,不再维护。没有建议的替代包。

扩展了 Doctrine 与 Symfony 集成的功能,例如允许仓库有额外的构造函数参数,并通过容器进行幕后检索/实例化。

安装次数: 12,943

依赖者: 0

建议者: 0

安全: 0

星星: 0

关注者: 25

分支: 0

开放问题: 1

类型: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

MIT 许可证下授权。

扩展了 Doctrine 与 Symfony 集成的功能。这包括

  • 允许仓库有额外的构造函数参数,并通过容器进行幕后检索/实例化。

要求

  • PHP >= 7.0
  • Symfony >= 2.7

安装

使用 Composer 需要此包

composer require lendable/doctrine-extensions-bundle

启用此包

<?php
// app/AppKernel.php

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

用法

带有依赖的仓库

一个具有额外构造函数参数的仓库,例如

<?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;
    }
}

应该配置为通知包如何获取这些额外的依赖。

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'

参数可以是

  • 原始标量。
  • 参数引用 (%wrapped%).
  • 服务引用 (@prefixed).
  • 上述任何一种的索引/关联数组。

现在可以通过 Doctrine 的 RegistryEntityManager 正常检索仓库。

<?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);