PHPackages                             roukmoute/sqids-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. roukmoute/sqids-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

roukmoute/sqids-bundle
======================

Integrates sqids/sqids in a Symfony project

v0.9.0(5mo ago)260[1 issues](https://github.com/roukmoute/sqids-bundle/issues)MITPHPPHP ^8.1CI passing

Since Aug 2Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/roukmoute/sqids-bundle)[ Packagist](https://packagist.org/packages/roukmoute/sqids-bundle)[ RSS](/packages/roukmoute-sqids-bundle/feed)WikiDiscussions main Synced today

READMEChangelog (9)Dependencies (17)Versions (11)Used By (0)

SqidsBundle
===========

[](#sqidsbundle)

[![CI](https://github.com/roukmoute/sqids-bundle/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/roukmoute/sqids-bundle/actions/workflows/unit-tests.yml)[![Latest Stable Version](https://camo.githubusercontent.com/7d9963c98a2b89e3ec32c918c568efd28740f5157613165a150bd546227bf39f/68747470733a2f2f706f7365722e707567782e6f72672f726f756b6d6f7574652f73716964732d62756e646c652f762f737461626c65)](https://packagist.org/packages/roukmoute/sqids-bundle)[![License](https://camo.githubusercontent.com/1c02563194e39f33d5a77f0e7581f0e5928fc82066cfb1da9775b5cfe35b22c8/68747470733a2f2f706f7365722e707567782e6f72672f726f756b6d6f7574652f73716964732d62756e646c652f6c6963656e7365)](https://packagist.org/packages/roukmoute/sqids-bundle)

Integrates [Sqids](https://sqids.org/) into your Symfony project.

Sqids (pronounced "squids") generates short unique identifiers from numbers. These IDs are URL-safe, can encode several numbers, and do not contain common profanity words.

This is the official successor to [Hashids](https://hashids.org/). If you are starting a new project, use Sqids instead of Hashids.

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

[](#installation)

```
composer require roukmoute/sqids-bundle
```

If you're using Symfony Flex, the bundle will be automatically registered. Otherwise, add it to your `config/bundles.php`:

```
return [
    // ...
    Roukmoute\SqidsBundle\RoukmouteSqidsBundle::class => ['all' => true],
];
```

Configuration
-------------

[](#configuration)

Create `config/packages/roukmoute_sqids.yaml`:

```
roukmoute_sqids:
    alphabet: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'  # Custom alphabet
    min_length: 0          # Minimum length of generated sqids
    blocklist: null        # Path to a JSON file containing blocked words, or null to use defaults
    passthrough: false     # Pass decoded value to next resolver (for Doctrine integration)
    auto_convert: false    # Automatically decode route parameters matching int arguments
```

### Configuration Options

[](#configuration-options)

OptionTypeDefaultDescription`alphabet`stringDefault Sqids alphabetCharacters used to generate sqids. Must contain at least 3 unique characters.`min_length`int0Minimum length of generated sqids.`blocklist`string|nullnullPath to a JSON file containing words to avoid in generated sqids.`passthrough`boolfalseWhen true, sets the decoded value in request attributes for the next resolver (useful with Doctrine).`auto_convert`boolfalseWhen true, automatically attempts to decode any route parameter matching an int argument name.Usage
-----

[](#usage)

### Basic Encoding/Decoding

[](#basic-encodingdecoding)

Inject `SqidsInterface` into your service or controller:

```
use Sqids\SqidsInterface;

class MyService
{
    public function __construct(private SqidsInterface $sqids)
    {
    }

    public function encode(int $id): string
    {
        return $this->sqids->encode([$id]);
    }

    public function decode(string $sqid): int
    {
        $decoded = $this->sqids->decode($sqid);
        return $decoded[0];
    }
}
```

### Controller Argument Resolution

[](#controller-argument-resolution)

#### Using the `#[Sqid]` Attribute

[](#using-the-sqid-attribute)

The `#[Sqid]` attribute automatically decodes sqid route parameters:

```
use Roukmoute\SqidsBundle\Attribute\Sqid;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class UserController
{
    #[Route('/users/{id}')]
    public function show(#[Sqid] int $id): Response
    {
        // $id is automatically decoded from the sqid in the URL
        // e.g., /users/UK → $id = 1
    }
}
```

#### Custom Parameter Name

[](#custom-parameter-name)

When the route parameter name differs from the argument name:

```
#[Route('/users/{sqid}')]
public function show(#[Sqid(parameter: 'sqid')] int $id): Response
{
    // The 'sqid' route parameter is decoded into $id
}
```

#### Using Aliases

[](#using-aliases)

Without any attribute, the resolver recognizes these aliases:

- `{sqid}` route parameter
- `{id}` route parameter

```
#[Route('/users/{id}')]
public function show(int $userId): Response
{
    // If {id} contains a valid sqid, $userId receives the decoded value
}
```

Note: Aliases are consumed once per request to avoid ambiguous resolution with multiple arguments.

### Multiple Sqids in a Single Route

[](#multiple-sqids-in-a-single-route)

Use the `_sqid_` prefix to decode multiple parameters:

```
#[Route('/users/{_sqid_user}/posts/{_sqid_post}')]
public function showPost(int $user, int $post): Response
{
    // Both $user and $post are decoded from their respective sqids
}
```

### Auto-Convert Mode

[](#auto-convert-mode)

Enable `auto_convert: true` in your configuration to automatically attempt decoding all route parameters that match `int` typed controller arguments:

```
roukmoute_sqids:
    auto_convert: true
```

```
#[Route('/users/{id}')]
public function show(int $id): Response
{
    // $id is automatically decoded if it looks like a valid sqid
    // If decoding fails, the resolver silently skips (no exception)
}
```

### Passthrough Mode (Doctrine Integration)

[](#passthrough-mode-doctrine-integration)

Enable `passthrough: true` to chain with Doctrine's `EntityValueResolver`:

```
roukmoute_sqids:
    passthrough: true
```

```
use App\Entity\User;

#[Route('/users/{id}')]
public function show(User $user): Response
{
    // The sqid is first decoded, then Doctrine fetches the User entity
}
```

The resolver decodes the sqid and sets the integer value in the request attributes, allowing Doctrine's resolver to find the entity.

Twig Integration
----------------

[](#twig-integration)

The bundle provides Twig filters and functions for encoding and decoding sqids.

### Filters

[](#filters)

```
{# Encode a single ID #}
{{ user.id | sqids_encode }}

{# Decode a sqid #}
{{ sqid | sqids_decode | first }}
```

### Functions

[](#functions)

```
{# Encode multiple IDs #}
{{ sqids_encode(1, 2, 3) }}

{# Use in a path #}

    View User

```

License
-------

[](#license)

This bundle is released under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance61

Regular maintenance activity

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~112 days

Recently: every ~0 days

Total

9

Last Release

165d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a864b67689c18f73803e34b6c4e269ab08395067ad635e1382ed96cc76f596a0?d=identicon)[roukmoute](/maintainers/roukmoute)

---

Top Contributors

[![roukmoute](https://avatars.githubusercontent.com/u/2140469?v=4)](https://github.com/roukmoute "roukmoute (46 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/roukmoute-sqids-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/roukmoute-sqids-bundle/health.svg)](https://phpackages.com/packages/roukmoute-sqids-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[symfony/framework-bundle

Provides a tight integration between Symfony components and the Symfony full-stack framework

3.6k251.7M11.5k](/packages/symfony-framework-bundle)[symfony/security-bundle

Provides a tight integration of the Security component into the Symfony full-stack framework

2.5k185.6M2.3k](/packages/symfony-security-bundle)[symfony/security-http

Symfony Security Component - HTTP Integration

1.7k177.2M376](/packages/symfony-security-http)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k51.2M335](/packages/api-platform-core)[symfony/ux-autocomplete

JavaScript Autocomplete functionality for Symfony

645.9M39](/packages/symfony-ux-autocomplete)

PHPackages © 2026

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