jonathanlight/meta-entity-builder-bundle
最新稳定版本:v1.1.2
Composer 安装命令:
composer require jonathanlight/meta-entity-builder-bundle
包简介
Symfony bundle that generates Doctrine entities from YAML schemas with smart update detection, custom code preservation, and automatic backups
README 文档
README
A Symfony bundle that generates Doctrine entities from YAML schemas with smart update detection, custom code preservation, and automatic backups.
Features
- YAML-based schema definition — Define your entities in a clean YAML format
- Smart update detection — Only regenerates entities when the schema changes (MD5 checksums)
- Custom code preservation — Code between
// @custom-code-startand// @custom-code-endmarkers is preserved across regeneration - Automatic backups — Timestamped backups before any file is overwritten
- PHP 8 attributes — Generated entities use modern Doctrine ORM attributes (
#[ORM\Entity],#[ORM\Column], etc.) - Fluent setters — All setters return
$thisfor method chaining - Collection helpers — Automatic
add*/remove*methods for*ToManyrelations - Event-driven — Dispatches events on entity generation and update
Requirements
- PHP 7.4+
- Symfony 5.4 | 6.x | 7.x
- Doctrine ORM 2.10+ | 3.x
Installation
composer require jonathanlight/meta-entity-builder-bundle
Configuration
# config/packages/meta_entity_builder.yaml meta_entity_builder: schema_path: '%kernel.project_dir%/config/entities.yaml' entity_namespace: 'App\Entity' entity_directory: '%kernel.project_dir%/src/Entity' backup_enabled: true backup_directory: '%kernel.project_dir%/var/backups/entities' generate_repository: true repository_namespace: 'App\Repository' strict_mode: true
Schema Definition
Create your entity definitions in YAML:
# config/entities.yaml entities: User: table: users repository: App\Repository\UserRepository properties: id: type: integer id: true autoIncrement: true email: type: string length: 180 unique: true name: type: string length: 255 createdAt: type: datetime_immutable relations: posts: type: OneToMany targetEntity: Post mappedBy: author cascade: [persist, remove] orphanRemoval: true indexes: idx_email: [email] Post: table: posts properties: id: type: integer id: true autoIncrement: true title: type: string length: 255 content: type: text nullable: true published: type: boolean default: false relations: author: type: ManyToOne targetEntity: User inversedBy: posts joinColumn: name: author_id referencedColumnName: id
Usage
Generate entities
# Generate all entities php bin/console meta-generate:entity # Dry run (preview changes without writing files) php bin/console meta-generate:entity --dry-run # Force regeneration (ignore checksums) php bin/console meta-generate:entity --force # Generate a specific entity php bin/console meta-generate:entity --entity=User
Aliases available: meta:entity:generate, entity:generate
Custom Code Preservation
Generated entities include markers where you can add custom code:
class User { // ... generated properties and methods ... // @custom-code-start // Add your custom methods here — this block is preserved on regeneration public function getFullName(): string { return $this->firstName . ' ' . $this->lastName; } // @custom-code-end }
Events
The bundle dispatches the following events:
Meta\EntityBuilderBundle\Event\EntityGeneratedEvent— When a new entity is createdMeta\EntityBuilderBundle\Event\EntityUpdatedEvent— When an existing entity is updated
License
Apache License 2.0 — see LICENSE for details.
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-02-10