headsnet/doctrine-tools-bundle
Composer 安装命令:
composer require headsnet/doctrine-tools-bundle
包简介
Tools and helpers for using Doctrine in larger Symfony projects
README 文档
README
Various tools and helpers for using Doctrine ORM in larger Symfony projects.
Installation
composer require headsnet/doctrine-tools-bundle
If your Symfony installation does not auto-register bundles, add it manually:
// bundles.php return [ ... Headsnet\DoctrineToolsBundle\HeadsnetDoctrineToolsBundle::class => ['all' => true], ];
Features
- Dynamically Create Types For Standard Objects
- Auto-Register Custom Doctrine Type Mappings
- Auto-Register Carbon Doctrine Type Mappings
Dynamically Create Types For Standard Objects
Applying the #[DoctrineType] attribute to a class will generate a Doctrine mapping type for the object and register
it in the application. To configure this behaviour, you must specify where to look for the classes to auto-register.
headsnet_doctrine_tools: root_namespace: Headsnet\DoctrineToolsBundle custom_types: scan_dirs: - 'src/' # the default value
Currently the bundle supports the following standard types:
stringviaAbstractStringMappingTypeintegerviaAbstractIntegerMappingTypeuuidviaAbstractUuidMappingType
For example, we have a string backed value object:
namespace App\Domain\Model; use Headsnet\DoctrineToolsBundle\Attribute\DoctrineType; #[DoctrineType(name: 'person_name', type: 'string')] class PersonName { public function __construct( private readonly string $value ) { } public static function create(string $value): self { return new self($value); } public function asString(): string { return $this->value; } }
This will cause a PHP file to be generated that provides the Doctrine Mapping Type for the class - something like:
class PersonNameType extends \Headsnet\DoctrineToolsBundle\Types\StandardTypes\AbstractStringMappingType { public function getName(): string { return 'person_name'; } public function getClass(): string { return 'App\Domain\Model\PersonName'; } }
This file is created in src/_generated/ - you will want to add this directory to your .gitignore file.
Auto-Register Custom Doctrine Type Mappings
The bundle can auto-register custom Doctrine DBAL types, eliminating the need to specify them all in
config/packages/doctrine.yaml:
Define the directories to scan for Doctrine types:
headsnet_doctrine_tools: custom_mappings: scan_dirs: - 'src/Infra/Persistence/DBAL/Types'
Then add the #[DoctrineTypeMapping] attribute to the custom type class:
use Doctrine\DBAL\Types\Type; use Headsnet\DoctrineToolsBundle\Attribute\DoctrineMappingType; #[DoctrineTypeMapping] final class ReservationIdType extends Type { // defines "reservation_id" type }
This will register a custom type based on the class name - in this case the custom column type will be called
reservation_id.
To customise the type name, specify it in the #[DoctrineTypeMapping] attribute. The following will register a type
called my_reservation_id.
#[DoctrineTypeMapping(name: 'my_reservation_id')] final class ReservationIdType extends Type { // customised name "my_reservation_id" type }
Auto-Register Carbon datetime type mappings
If the nesbot/carbon package is installed, this package will automatically register the Doctrine types provided by
Carbon.
By default, it will overwrite the default Doctrine types for datetime and datetime_immutable with the Carbon
equivalents:
datetime_immutable: \Carbon\Doctrine\DateTimeImmutableType datetime: \Carbon\Doctrine\DateTimeType
If you wish the Carbon types to operate alongside the default DateTime and DateTimeImmutable types, set replace: false in the bundle configuration. This will result in additional types being defined for the Carbon columns.
carbon_immutable: \Carbon\Doctrine\DateTimeImmutableType carbon: \Carbon\Doctrine\DateTimeType
If you wish to completely disable this behaviour, set enabled: false in the bundle configuration.
headsnet_doctrine_tools: carbon_mappings: enabled: true replace: true
Contributions
Contributions are welcome via Pull Requests. Please include a single change in each PR.
License
Released under the MIT License.
headsnet/doctrine-tools-bundle 适用场景与选型建议
headsnet/doctrine-tools-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.71k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 05 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「orm」 「symfony」 「php」 「doctrine」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 headsnet/doctrine-tools-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 headsnet/doctrine-tools-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 headsnet/doctrine-tools-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
The bundle for easy using json-rpc api on your project
Bundle Symfony DaplosBundle
PeskyORM - annoying ORM that contains tons of exceptions and throws them when anything goes wrong
An ORM solution for Salesforce Object Query Language (SOQL)
统计信息
- 总下载量: 18.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-23