chamber-orchestra/doctrine-extensions-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

chamber-orchestra/doctrine-extensions-bundle

Composer 安装命令:

composer require chamber-orchestra/doctrine-extensions-bundle

包简介

Lightweight Symfony Doctrine ORM extensions for PostgreSQL — entity traits, soft-delete filter, repository base classes, decimal type, random() DQL

README 文档

README

PHP Composer codecov PHPStan Latest Stable Version License Symfony 8 Doctrine ORM PostgreSQL PHP 8.5

Lightweight Symfony bundle providing reusable Doctrine ORM extensions for PostgreSQL: entity traits with matching contract interfaces, a soft-delete SQL filter, extended repository base classes, a custom decimal DBAL type, and a random() DQL function.

Requirements

  • PHP ^8.5
  • Symfony 8.0
  • Doctrine ORM 3 / DoctrineBundle 3.2
  • PostgreSQL

Installation

composer require chamber-orchestra/doctrine-extensions-bundle

If you are not using Symfony Flex:

// config/bundles.php
return [
    ChamberOrchestra\DoctrineExtensionsBundle\ChamberOrchestraDoctrineExtensionsBundle::class => ['all' => true],
];

Features

Entity Traits & Contract Interfaces

Each trait has a corresponding interface in Contracts\Entity. Implement the interface and use the trait:

use ChamberOrchestra\DoctrineExtensionsBundle\Contracts\Entity\IdInterface;
use ChamberOrchestra\DoctrineExtensionsBundle\Contracts\Entity\SoftDeleteInterface;
use ChamberOrchestra\DoctrineExtensionsBundle\Contracts\Entity\ToggleInterface;
use ChamberOrchestra\DoctrineExtensionsBundle\Entity\IdTrait;
use ChamberOrchestra\DoctrineExtensionsBundle\Entity\SoftDeleteTrait;
use ChamberOrchestra\DoctrineExtensionsBundle\Entity\ToggleTrait;
use ChamberOrchestra\DoctrineExtensionsBundle\Entity\VersionTrait;

class Article implements IdInterface, SoftDeleteInterface, ToggleInterface
{
    use IdTrait;
    use SoftDeleteTrait;
    use ToggleTrait;
    use VersionTrait;
}
Trait Interface Fields & Methods
IdTrait IdInterface UUID primary key (caller-assigned). getId(): Uuid
GeneratedIdTrait GeneratedIdInterface UUID primary key (auto-generated, nullable before persist). getId(): ?Uuid
SoftDeleteTrait SoftDeleteInterface deletedDatetime column. isDeleted(), delete(), restore()
ToggleTrait ToggleInterface enabled boolean column. isEnabled(), toggle(), enable(), disable()
VersionTrait Doctrine @Version column using DatePoint (microsecond precision). getVersion()

Soft-Delete Filter

Automatically appends deleted_datetime IS NULL to queries for entities implementing SoftDeleteInterface. Bypass per entity when needed:

$filter = $entityManager->getFilters()->enable('soft_delete');
$filter->disableForEntity(Article::class);   // include soft-deleted articles
$filter->enableForEntity(Article::class);    // re-enable filtering

Repository Base Classes

Two base classes provide getOneBy() and indexBy() out of the box:

  • ServiceEntityRepository — extends Doctrine bundle's ServiceEntityRepository, adds $cacheable parameter to createQueryBuilder()
  • EntityRepository — extends Doctrine ORM's EntityRepository, implements ServiceEntityRepositoryInterface
use ChamberOrchestra\DoctrineExtensionsBundle\Repository\ServiceEntityRepository;

class ArticleRepository extends ServiceEntityRepository
{
    // getOneBy(criteria, orderBy) — throws EntityNotFoundException if not found
    // indexBy(criteria, orderBy, field) — returns array of field values matching criteria
}

Custom Decimal DBAL Type

DecimalType overrides Doctrine's DecimalType to ensure convertToPHPValue() always returns ?string with scalar type validation.

DQL Random Function (PostgreSQL)

Maps random() DQL to PostgreSQL random():

# config/packages/doctrine.yaml
doctrine:
    orm:
        dql:
            numeric_functions:
                random: ChamberOrchestra\DoctrineExtensionsBundle\Function\Random
$qb->select('a')->from(Article::class, 'a')->orderBy('random()');

Testing

composer test

License

MIT

统计信息

  • 总下载量: 2.62k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固