chamber-orchestra/doctrine-slug-bundle
#[Slug], #[SlugGenerator]), which is intuitive for teams already using Doctrine annotations/attributes. This avoids invasive changes to business logic.prePersist, preUpdate) to auto-generate slugs and resolve collisions (e.g., appending -1, -2). This is a robust approach but assumes entities are persisted via Doctrine’s event system (not raw SQL or custom repositories).config/bundles.php).#[Slug] to entities, which is a breaking change if the codebase lacks PHP 8.4 attributes. Teams using older PHP versions or annotations would need migration effort.prePersist/preUpdate could introduce latency if entities have complex slug logic (e.g., multi-field concatenation). Benchmarking is recommended for high-throughput systems.TestKernel.php). Integration risks include:
#[Slug] attributes disrupt existing workflows (e.g., CI pipelines, IDE tooling)?prePersist/preUpdate logic that could conflict with the bundle’s event subscribers?-1, -2) acceptable, or does the application need custom resolution (e.g., keyword replacement)?gedmo/doctrine-extensions, beberlei/doctrineextensions)? What were the trade-offs?Extension/Bundle system with Laravel’s service providers.#[Slug] attributes with Laravel annotations or custom traits.| Step | Action | Effort | Risks |
|---|---|---|---|
| 1 | Assess Compatibility | Low | High |
| - Verify Symfony/Doctrine versions meet requirements (6.4+, 3.0+). | |||
- Audit entities for custom prePersist/preUpdate logic. |
|||
| 2 | Add Dependencies | Low | Medium |
- Install via Composer: composer require chamber-orchestra/doctrine-slug-bundle. |
|||
- Enable bundle in config/bundles.php. |
|||
| 3 | Configure Slugs | Medium | High |
- Add #[Slug] attributes to target entities (e.g., #[Slug(fields: ['title', 'name'])]). |
|||
- Customize generators/config via config/packages/chamber_orchestra_doctrine_slug.yaml. |
|||
| 4 | Test Collision Handling | High | Critical |
| - Validate slug generation for edge cases (e.g., duplicate titles, special characters). | |||
| - Test backfilling existing entities (if applicable). | |||
| 5 | Optimize Performance | Medium | Low |
| - Benchmark slug generation under load. | |||
| - Consider caching or async generation for high-volume writes. |
prePersist/preUpdate. Conflicts may arise if:
slug: string). No migrations are provided; teams must handle schema changes.#[Slug] on simple fields (e.g., title) before complex multi-field slugs.prePersist duration).src/ codebase and maintaining forks.prePersist/preUpdate. Mitigation:
slug column is indexed for queries.| Scenario | Impact | Mitigation |
|---|---|---|
| Duplicate Slug Collision | Infinite loops or failed saves. | Custom collision resolution (e.g., UUID suffixes). |
| Database Lock Contention | Timeouts during high write loads. | Optimistic locking or retry logic. |
| Attribute Parsing Errors | Slug generation fails silently. | Validate entities with #[Slug] at runtime. |
| Schema Mismatch | Slug field missing in entities. | Pre-deployment schema validation. |
| PHP 8.4+ Runtime Errors | Attribute syntax fails. | CI |
How can I help you explore Laravel packages today?