alister/reserved-names-bundle
Pros:
check and cleanusername), aligning with Symfony’s dependency injection principles.Cons:
@todo), requiring manual integration with Symfony’s validation system.AppKernel.php registration, YAML config).ReservedNames service), but loses dependency injection benefits.use Symfony\Component\Validator\Constraint;
class ReservedNameConstraint extends Constraint {
public function validatedBy() { return 'reserved_name'; }
}
Then register a validator service to use alister_reserved_names.check.Attribute constraints, Attribute-based services).Symfony Version Compatibility:
AppKernel → Kernel)?Validation Workflow:
ConstraintViolation or return a boolean for custom handling?Reserved Name Management:
Performance:
myname_123 → myname) impact performance for high-throughput systems?Alternatives:
UniqueEntity with a reserved-name table])?config/packages/ instead of AppKernel, autowiring, PHP 8.x syntax).composer.json to target Symfony 6+/7+.AppKernel registration with config/packages/alister_reserved_names.yaml.ReservedNames class) can be extracted and used standalone, but loses DI and config benefits.$reservedNames = new \Alister\ReservedNamesBundle\Services\ReservedNames(['myname', 'admin']);
if ($reservedNames->isReserved('myname_123')) { ... }
composer require alister/reserved-names-bundle).AppKernel.php.config.yml.alister_reserved_names.check service into controllers/forms.config/packages/alister_reserved_names.yaml.#[Autowire]).# config/services.yaml
services:
App\Validator\Constraints\ReservedNameValidator:
tags: [validator.constraint_validator]
// src/Validator/Constraints/ReservedName.php
#[Attribute]
class ReservedName extends Constraint { ... }
// src/Validator/Constraints/ReservedNameValidator.php
class ReservedNameValidator extends ConstraintValidator {
public function __construct(private ReservedNames $reservedNames) {}
public function validate($value, Constraint $constraint) {
if ($this->reservedNames->isReserved($value)) {
$this->context->buildViolation($constraint->message)
->addViolation();
}
}
}
AppKernel removal, container syntax).#[Attribute] support.alister_reserved_names.cleanusername to normalize input (e.g., strip trailing _123).isReserved().@ReservedName constraint) or use manually in forms/controllers.in_array() or similar, which is O(n). For large lists (>10,000 names), consider:
HashSet or trie for O(1) lookups.How can I help you explore Laravel packages today?