tourze/doctrine-indexed-bundle
Composer 安装命令:
composer require tourze/doctrine-indexed-bundle
包简介
A Symfony bundle that enhances Doctrine ORM with automatic index management using PHP 8 attributes
README 文档
README
A Symfony bundle that enhances Doctrine ORM with automatic index management.
Features
- Automatically adds indexes to specified entity properties
- Supports regular, fulltext, and unique indexes
- Smart index naming strategy, automatically handles long table names
- Attribute-based configuration (PHP 8 attributes), no extra config files
- Zero configuration required, works out-of-the-box
Requirements
- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine Bundle 2.13 or higher
Installation
composer require tourze/doctrine-indexed-bundle
Usage
- Register the bundle in
config/bundles.php:
return [ // ... Tourze\DoctrineIndexedBundle\DoctrineIndexedBundle::class => ['all' => true], ];
- Use attributes to mark entity fields that require indexes:
use Tourze\DoctrineIndexedBundle\Attribute\IndexColumn; use Tourze\DoctrineIndexedBundle\Attribute\FulltextColumn; use Tourze\DoctrineIndexedBundle\Attribute\UniqueColumn; class YourEntity { #[ORM\Column] #[IndexColumn] // Regular index private string $name; #[ORM\Column(type: 'text')] #[FulltextColumn] // Fulltext index private string $description; #[ORM\Column] #[UniqueColumn] // Unique index private string $email; }
Configuration
This bundle requires no configuration and works out-of-the-box. However,
you can customize index names by providing a name parameter to the attributes:
#[IndexColumn(name: 'custom_index_name')] private string $field;
Index Naming Convention
The bundle automatically generates index names as follows:
- Regular index:
{table_name}_idx_{column_name} - Fulltext index:
{table_name}_fulltext_{column_name} - Unique constraint:
{table_name}_unique_{column_name}
If the generated name exceeds the maximum length (64 characters), the bundle will use MD5 hashing to create a shorter name while maintaining uniqueness.
Advanced Usage
Custom Index Names
You can specify custom names for indexes:
#[IndexColumn(name: 'search_idx')] private string $searchable; #[FulltextColumn(name: 'content_fulltext')] private string $content; #[UniqueColumn(name: 'email_unique')] private string $email;
Multiple Attributes
You can combine different index types on the same entity:
class Product { #[ORM\Column] #[IndexColumn] // For searching #[UniqueColumn] // For uniqueness private string $sku; #[ORM\Column(type: 'text')] #[FulltextColumn] // For full-text search #[IndexColumn] // For regular search too private string $description; }
How It Works
- Listens to Doctrine's
loadClassMetadataevent and scans entity properties - Checks for
IndexColumn,FulltextColumn, orUniqueColumnattributes on properties - Automatically adds the corresponding index to the entity field
- Naming strategy ensures compatibility with DBMS index name length limits
Contributing
Feel free to submit issues and pull requests to help improve this bundle.
License
MIT License
tourze/doctrine-indexed-bundle 适用场景与选型建议
tourze/doctrine-indexed-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36.9k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 03 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tourze/doctrine-indexed-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tourze/doctrine-indexed-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 36.9k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 19
- 依赖项目数: 125
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-24