PHPackages                             chamber-orchestra/doctrine-slug-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. chamber-orchestra/doctrine-slug-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

chamber-orchestra/doctrine-slug-bundle
======================================

Symfony bundle for generating unique, URL-friendly slugs for Doctrine ORM entities using PHP 8 attributes

v8.0.9(2mo ago)0199MITPHPPHP ^8.5CI passing

Since Jan 4Pushed 2mo agoCompare

[ Source](https://github.com/chamber-orchestra/doctrine-slug-bundle)[ Packagist](https://packagist.org/packages/chamber-orchestra/doctrine-slug-bundle)[ Docs](https://github.com/chamber-orchestra/doctrine-slug-bundle)[ RSS](/packages/chamber-orchestra-doctrine-slug-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (13)Used By (0)

[![PHP Composer](https://github.com/chamber-orchestra/doctrine-slug-bundle/actions/workflows/php.yml/badge.svg)](https://github.com/chamber-orchestra/doctrine-slug-bundle/actions/workflows/php.yml)[![codecov](https://camo.githubusercontent.com/62bc8d75e50130af20e259a71d12d4b0c4e1330304f486b7ec37aecc4248738c/68747470733a2f2f636f6465636f762e696f2f67682f6368616d6265722d6f72636865737472612f646f637472696e652d736c75672d62756e646c652f67726170682f62616467652e737667)](https://codecov.io/gh/chamber-orchestra/doctrine-slug-bundle)[![PHPStan](https://camo.githubusercontent.com/14995ff65edea59395c224e37e4fc66f91c1e601c1a58311e3c6f38c4fe37feb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c2532306d61782d627269676874677265656e)](https://phpstan.org/)[![Latest Stable Version](https://camo.githubusercontent.com/d71c1709110ccb8f19dd28e562d9746032bdce91f81bc00ecbe80a7110b8f5fe/68747470733a2f2f706f7365722e707567782e6f72672f6368616d6265722d6f72636865737472612f646f637472696e652d736c75672d62756e646c652f76)](https://packagist.org/packages/chamber-orchestra/doctrine-slug-bundle)[![License](https://camo.githubusercontent.com/c0342c9b14faf1d79317e2aafd246094a179bb06f197d060bd8af7da08fd5d17/68747470733a2f2f706f7365722e707567782e6f72672f6368616d6265722d6f72636865737472612f646f637472696e652d736c75672d62756e646c652f6c6963656e7365)](https://packagist.org/packages/chamber-orchestra/doctrine-slug-bundle)[![Symfony 8](https://camo.githubusercontent.com/a7d902ab1b809ccff2eaa21df5aadd13f1b13e22e4e4c49f40d020b918f48e05/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d382d707572706c653f6c6f676f3d73796d666f6e79)](https://camo.githubusercontent.com/a7d902ab1b809ccff2eaa21df5aadd13f1b13e22e4e4c49f40d020b918f48e05/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d382d707572706c653f6c6f676f3d73796d666f6e79)[![PHP 8.5](https://camo.githubusercontent.com/38189c74fa19d38a84282702897dcd5bf0e54f8ee6be5cb02aa9a3a1f5711862/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e352d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/38189c74fa19d38a84282702897dcd5bf0e54f8ee6be5cb02aa9a3a1f5711862/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e352d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)[![Doctrine ORM 3](https://camo.githubusercontent.com/c3b011e1ff8aaf3e33c9a56be4494e40e9f95b2ffbd0dd03d6ade1e53eac9019/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f637472696e652532304f524d2d332d6f72616e67653f6c6f676f3d646f637472696e65266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/c3b011e1ff8aaf3e33c9a56be4494e40e9f95b2ffbd0dd03d6ade1e53eac9019/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f637472696e652532304f524d2d332d6f72616e67653f6c6f676f3d646f637472696e65266c6f676f436f6c6f723d7768697465)

Doctrine Slug Bundle
====================

[](#doctrine-slug-bundle)

A Symfony bundle that automatically generates unique, URL-friendly slugs for Doctrine ORM entities using native PHP 8 attributes. Slugs are created on persist and optionally regenerated on update, with built-in collision resolution (`hello-world`, `hello-world-1`, `hello-world-2`, ...).

Features
--------

[](#features)

- Declarative configuration via `#[Slug]` PHP attribute
- Automatic unique slug generation with collision suffixes
- Optional slug regeneration on entity update
- Configurable separator character and column length
- Reusable `SlugTrait` for common name/slug entity patterns
- Mapping validation (unique constraint, nullable consistency, source type checking)
- Integration with `chamber-orchestra/metadata-bundle` and Doctrine event listeners

Requirements
------------

[](#requirements)

- PHP 8.5+
- Symfony 8.0+
- Doctrine ORM 3.6+ / DoctrineBundle 3.2+
- `chamber-orchestra/metadata-bundle` 8.0.\*

Installation
------------

[](#installation)

```
composer require chamber-orchestra/doctrine-slug-bundle
```

If Symfony Flex does not auto-register the bundle, add it manually:

```
// config/bundles.php
return [
    ChamberOrchestra\DoctrineSlugBundle\ChamberOrchestraDoctrineSlugBundle::class => ['all' => true],
];
```

Usage
-----

[](#usage)

Annotate a property with the `#[Slug]` attribute. The slug column **must** be `unique`.

```
namespace App\Entity;

use ChamberOrchestra\DoctrineSlugBundle\Mapping\Attribute\Slug;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class Post
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private ?int $id = null;

    #[ORM\Column(type: 'string', length: 255)]
    private string $name = '';

    #[ORM\Column(type: 'string', length: 255, unique: true)]
    #[Slug(source: 'name')]
    private string $slug = '';

    // getters ...
}
```

### Attribute Options

[](#attribute-options)

OptionTypeDefaultDescription`source`string—Source property name for slug generation`update`bool`false`Regenerate slug when the source field changes`separator`string`-`Word separator character### Using the SlugTrait

[](#using-the-slugtrait)

For entities with a standard `name`/`slug` pattern:

```
use ChamberOrchestra\DoctrineSlugBundle\Contracts\Entity\SlugInterface;
use ChamberOrchestra\DoctrineSlugBundle\Entity\SlugTrait;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class Post implements SlugInterface
{
    use SlugTrait;

    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private ?int $id = null;
}
```

The trait provides `$name` (varchar 127), `$slug` (varchar 255, unique) with `getName()`, `setName()`, and `getSlug()` accessors.

### Mapping Constraints

[](#mapping-constraints)

The bundle validates mappings at metadata load time:

- Slug column must have `unique: true`
- Source property must exist and be a string type (`string`, `text`, or `ascii_string`)
- If source is nullable, slug must also be nullable
- Separator must be exactly one character

Development
-----------

[](#development)

```
composer test       # Run PHPUnit test suite
composer analyse    # Run PHPStan static analysis (level max)
composer cs-fix     # Fix code style with PHP-CS-Fixer
composer cs-check   # Verify code style (dry-run)
```

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance85

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

10

Last Release

79d ago

PHP version history (2 changes)v8.0.1PHP ^8.4

v8.0.2PHP ^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/44037eb1c8dc2c4fa9871ac213653f33e22a9348dcec7132df07cc71933f2a2e?d=identicon)[wtorsi](/maintainers/wtorsi)

---

Top Contributors

[![wtorsi](https://avatars.githubusercontent.com/u/2115840?v=4)](https://github.com/wtorsi "wtorsi (11 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

doctrinedoctrine-ormphpseoslugsymfonysymfony-bundleurl-friendlyslugslugifysymfonydoctrineseoSymfony Bundledoctrine-ormphp-attributesUnique Slugurl-friendly

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/chamber-orchestra-doctrine-slug-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/chamber-orchestra-doctrine-slug-bundle/health.svg)](https://phpackages.com/packages/chamber-orchestra-doctrine-slug-bundle)
```

###  Alternatives

[ahmed-bhs/doctrine-doctor

Runtime analysis tool for Doctrine ORM integrated into Symfony Web Profiler. Unlike static linters, it analyzes actual query execution at runtime to detect performance bottlenecks, security vulnerabilities, and best practice violations during development with real execution context and data.

813.1k](/packages/ahmed-bhs-doctrine-doctor)[andanteproject/soft-deletable-bundle

A Symfony Bundle to handle soft deletable with Doctrine Entities

1028.3k](/packages/andanteproject-soft-deletable-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
