PHPackages                             mikamatto/reserved-values-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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. mikamatto/reserved-values-bundle

ActiveSymfony-bundle[Validation &amp; Sanitization](/categories/validation)

mikamatto/reserved-values-bundle
================================

A Symfony bundle to restrict reserved values in form fields such as usernames or slugs, with support for exact matches and regular expressions.

v2.1.1(1y ago)235MITPHPPHP ^8.0

Since Oct 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mikamatto/ReservedValuesBundle)[ Packagist](https://packagist.org/packages/mikamatto/reserved-values-bundle)[ RSS](/packages/mikamatto-reserved-values-bundle/feed)WikiDiscussions main Synced 1mo ago

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

ReservedValuesBundle
====================

[](#reservedvaluesbundle)

**ReservedValuesBundle** is a Symfony bundle that allows you to restrict the use of reserved values across different fields by adding custom validation rules. You can specify exact restrictions or use patterns to block specific values, applicable to any field, such as usernames, slugs, or any other user-defined attributes that require validation.

Features
--------

[](#features)

- Block specific exact usernames (e.g., `admin`, `support`).
- Block usernames based on patterns (e.g., usernames starting with `admin` or `support`).
- Support for multiple keys to apply a different set of restrictions to different fields.
- Automatic validation bypass for admin users (hierarchically) based on a configurable role.

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

[](#installation)

### 1. Require the Bundle

[](#1-require-the-bundle)

You can install the bundle using Composer:

```
composer require mikamatto/reserved-values-bundle
```

### 2. Enable the Bundle

[](#2-enable-the-bundle)

If you're using Symfony Flex, the bundle will be enabled automatically. Otherwise, you may need to manually enable it in your `config/bundles.php`:

```
return [
    // Other bundles...
    Mikamatto\ReservedValuesBundle\ReservedValuesBundle::class => ['all' => true],
];
```

### 3. Configuration

[](#3-configuration)

You need to create a configuration file for the bundle at `config/packages/reserved_values.yaml`.

The format of the configuration file is as follows:

```
reserved_values:
    # Optional: Configure the roles that can bypass validation
    bypass_roles:
        - ROLE_ADMIN # The default value if not specified
        - ROLE_SYS_ADMIN
        - ROLE_DATA_ADMIN

    keys:
        username:
            exact:
                - _error
                - _wdt
                - _profiler
                - account
                - configuration
                - contact
                - posts
                - dmca
                - login
                - logout
                - page
                - password
                - register
                - scheduler
                - settings
                - slugger
                - sfw
                - user

            patterns:
                - '^admin.*'    # Bans 'admin', 'administrator', 'admin123', etc.
                - '^support.*'  # Bans 'support', 'support1', 'support-team', etc.

        slug:
            exact:
                - example-slug
                - another-slug

            patterns:
                - '^draft-.*'   # Bans 'draft-post', 'draft-article', etc.
```

#### Configuration Options

[](#configuration-options)

- **key**: This is a custom identifier for the field (e.g., username, slug) to which the restrictions apply.
- **exact**: This section contains a list of values that are strictly forbidden for the specified key. Users attempting to use any of these values will receive a validation error.
- **patterns**: This section allows you to specify regular expressions for matching values that should be restricted. Any value that matches one of the defined patterns will also trigger a validation error.
- **bypass\_roles**: This is an optional configuration that specifies the roles required to bypass the validation. If not specified, the default value is `ROLE_ADMIN`.

Make sure to define at least one of the options under each key in your configuration file. If both sections are left empty for a key, no values will be restricted for that field.

### 4. Applying the Validation to an Entity

[](#4-applying-the-validation-to-an-entity)

To apply the `ReservedValues` validation to your entity, you can use either annotations or attributes. The constraint accepts:

- `key`: (required) The key for the validation rules defined in your configuration
- `bypassRoles`: (optional) Additional roles that can bypass validation for this specific field. Can be a single role as string or an array of roles. Defaults to an empty array, meaning only global bypass roles from configuration will apply.

Here are examples using both methods:

#### Using Annotations

[](#using-annotations)

```
namespace App\Entity;

use Mikamatto\ReservedValuesBundle\Validator\Constraints\ReservedValues;
use Symfony\Component\Validator\Constraints as Assert;

class User
{
    /**
     * @Assert\NotBlank
     * @ReservedValues(key="username")  // Only global bypass roles apply
     */
    private $username;

    /**
     * @Assert\NotBlank
     * @ReservedValues(key="username", bypassRoles={"ROLE_USER_ADMIN"})  // Global + field-specific roles
     */
    private $anotherField;
}
```

#### Using Attributes (Symfony 6.0+)

[](#using-attributes-symfony-60)

```
namespace App\Entity;

use Mikamatto\ReservedValuesBundle\Validator\Constraints\ReservedValues;
use Symfony\Component\Validator\Constraints as Assert;

class User
{
    #[Assert\NotBlank]
    #[ReservedValues('username')]  // Only global bypass roles apply
    private $username;

    #[Assert\NotBlank]
    #[ReservedValues('username', ['ROLE_USER_ADMIN', 'ROLE_CUSTOM_ADMIN'])]  // Multiple field-specific roles
    private $secondField;

    #[Assert\NotBlank]
    #[ReservedValues('username', 'ROLE_USER_ADMIN')]  // Single field-specific role
    private $thirdField;
}
```

The validation will be bypassed if the user has either:

- Any of the global roles defined in the configuration under `bypass_roles`
- Any of the field-specific roles defined in the attribute (if specified)

This allows for both global and field-specific role-based validation bypass while maintaining backward compatibility with existing code that only uses the `key` parameter.

Upgrading from 1.x to 2.0
-------------------------

[](#upgrading-from-1x-to-20)

Version 2.0 introduces a new configuration structure and the ability to configure multiple bypass roles. Here's how to upgrade your existing configuration:

### Configuration Changes

[](#configuration-changes)

#### Before (1.x)

[](#before-1x)

```
reserved_values:
    username:
        exact:
            - admin
            - support
        patterns:
            - '^admin.*'
```

#### After (2.0)

[](#after-20)

```
reserved_values:
    # Optional: Configure roles that can bypass validation
    bypass_roles:
        - ROLE_ADMIN # The default value if not specified
        - ROLE_SYS_ADMIN
        - ROLE_DATA_ADMIN

    keys:
        username:
            exact:
                - admin
                - support
            patterns:
                - '^admin.*'
```

### Breaking Changes

[](#breaking-changes)

1. All validation rules must now be placed under the `keys` section
2. The role-based validation bypass is now configurable through `bypass_roles`
3. The configuration structure has changed to better separate concerns

### Migration Steps

[](#migration-steps)

1. Add the new `keys` root node to your configuration
2. Move all your existing validation rules under the `keys` section
3. If you want to customize which roles can bypass validation, add the `bypass_roles` configuration
4. If you don't specify `bypass_roles`, it defaults to `['ROLE_ADMIN']`

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance45

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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 ~21 days

Recently: every ~8 days

Total

6

Last Release

456d ago

Major Versions

v1.1.1 → v2.0.02025-01-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b68bfb1904d505c75e0f3b866df0a96719bcb8268a7574ea249eb7cb76dd510?d=identicon)[mikamatto](/maintainers/mikamatto)

---

Top Contributors

[![mikamatto](https://avatars.githubusercontent.com/u/45991183?v=4)](https://github.com/mikamatto "mikamatto (7 commits)")

---

Tags

reservedslugreservedusernamesreservedwordsrestrictedwordssymfonysymfony-bundle

### Embed Badge

![Health badge](/badges/mikamatto-reserved-values-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/mikamatto-reserved-values-bundle/health.svg)](https://phpackages.com/packages/mikamatto-reserved-values-bundle)
```

###  Alternatives

[rollerworks/password-strength-bundle

Password-strength validator bundle for Symfony

1433.7M6](/packages/rollerworks-password-strength-bundle)[j-ben87/parsley-bundle

Convert Symfony constraints into data-attributes for client-side validation with Parsley.

1432.7k](/packages/j-ben87-parsley-bundle)[superbrave/gdpr-bundle

A Symfony bundle for using entity annotations according to GDPR requirements and anonymizing/exporting data

1120.0k](/packages/superbrave-gdpr-bundle)

PHPackages © 2026

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