- Can I use alister/reserved-names-bundle directly in Laravel without Symfony?
- No, this bundle is designed for Symfony and requires its dependency injection container. For Laravel, you’d need to extract the core logic (e.g., `ReservedNames` and `CleanUserNames` services) and adapt them to Laravel’s service container. The bundle’s YAML configuration would also need manual conversion.
- How do I integrate this with Laravel’s validation system?
- Since this bundle lacks a built-in validator constraint, you’ll need to create a custom Laravel validation rule. Use the `alister_reserved_names.check` service (via Symfony bridge) in a custom rule class, then apply it to your username field. Example: `Validator::extend('reserved_name', function ($attribute, $value, $parameters) { ... })`.
- What Laravel/Symfony versions does this bundle support?
- The bundle officially supports Symfony 4.1–5.0 and PHP 7.x (likely 7.2–7.4). It has **no support for Symfony 6/7 or PHP 8.x**, so you’d need to fork and update dependencies (e.g., `symfony/dependency-injection`, `symfony/config`) if using newer versions. Laravel compatibility depends on your Symfony bridge setup.
- How do I configure custom reserved names in Laravel?
- Configure reserved names in `config/packages/alister_reserved_names.yaml` (Symfony 5+) or `app/config/config.yml` (Symfony 4). Use the `names` key with a list of strings, which are case-insensitive. For dynamic names (e.g., from a database), override the `ReservedNames` service to fetch names at runtime instead of using the YAML list.
- Will this bundle break if I upgrade Symfony from 5.0 to 6.x?
- Yes, this bundle is **not compatible with Symfony 6/7** due to deprecated components (e.g., `AppKernel`, older DI syntax). You’d need to fork the project, update `composer.json` to target Symfony 6+, and refactor container registration (e.g., replace `AppKernel.php` with `config/packages/`). Test thoroughly after migration.
- How does the 'noise character' stripping work, and can I disable it?
- The `cleanusername` service strips trailing digits, underscores (`_`), and hyphens (`-`) from usernames (e.g., `myname_123` → `myname`). This is used for a secondary check against reserved names. To disable it, override the `CleanUserNames` service in your DI container and modify its `clean()` method to return the input unchanged.
- Are there performance concerns with large reserved name lists?
- The bundle uses a simple array-based lookup for reserved names, which is efficient for small lists (<1,000 entries). For larger lists, consider optimizing by pre-compiling names into a hash set (e.g., `SplFixedArray`) or using a trie data structure. Case-insensitive matching adds overhead; if performance is critical, pre-process names to lowercase during initialization.
- Can I use this bundle alongside Laravel’s built-in username validation?
- Yes, this bundle is designed to work alongside other validation. Use it **after** basic checks (e.g., length, allowed characters) but **before** database uniqueness checks. For Laravel, integrate it into your validation pipeline via a custom rule or form request. Example: `Validator::make($data)->after(function ($validator) { ... })->validate();`
- What alternatives exist for reserved name validation in Laravel?
- For Laravel, consider: 1) A **custom validator rule** with a hardcoded array of reserved names (simpler, no Symfony dependency). 2) **Database-backed validation**: Store reserved names in a table and query them during registration. 3) **Laravel packages** like `spatie/laravel-validation` for reusable rules. This bundle is only worth the Symfony overhead if you need its cleaning logic or YAML config.
- How do I test this bundle in a Laravel project?
- Since this bundle isn’t natively Laravel-compatible, test its core logic by extracting the `ReservedNames` and `CleanUserNames` classes into your project. Mock the YAML config (e.g., use `config('alister_reserved_names.names')`) and test with PHPUnit. For Symfony integration, use a test container (as shown in the bundle’s README) or a Laravel-Symfony bridge like `symfony/var-dumper` for debugging.