alister / reserved-names-bundle
This bundle checks against a list of reserved names, & some variants
Installs: 202
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 1
Type:symfony-bundle
Requires
- symfony/config: ^4.1.4
- symfony/framework-bundle: ^4.1
Requires (Dev)
- phpmd/phpmd: ^2.6
- phpunit/phpunit: ^6.1
- roave/security-advisories: dev-master
- sebastian/phpcpd: ^3.0
- sensiolabs/security-checker: ^6.0
- squizlabs/php_codesniffer: ^3.0
- symfony/yaml: ^4.1
README
A bundled service to clean, and check, a given username against an (extensible) list of reserved words/usernames.
Note: This DOES NOT validate usernames. That should happen (and potentially disallow names) before getting to this stage.
Installation and use
-
Add to app/AppKernel.php
$bundles = array( new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), // ... many others new Alister\ReservedNamesBundle\AlisterReservedNamesBundle(), );
-
Add to app/config/config.yml
alister_reserved_names: names: # These keys will be lower-cased - myname - myothername - alister - private
-
Use
$username = 'myname_123'; $reserved = $this->container->get('alister_reserved_names.check'); if ($reserved->isReserved($username)) { echo "{$username} is reserved"; }
-
Services provided:
- alister_reserved_names.check
- Check username does not match a reserved name, before or after calling @cleanusername
- @see Alister\ReservedNamesBundle\Services\ReservedNames
- The code also strips off trailing 's', and then additional noise characters (digits, -, _) for a final test against the reserved names
- alister_reserved_names.cleanusername
- remove 'noise characters' around the given username
- EG: myname_123 becomes myname
- @see Alister\ReservedNamesBundle\Services\CleanUserNames
Included tests
Testing is done with the classes directly, and also via a container, to test the service initialisation. This also allows a check for the 'local reservations' - extra names that can be defined in the local application. The container-based test includes a micro-application to build the container, and so run the full test. How to create a test setup for a local test of the service.
@todo
Make a validator (from existing code) and put into this bundle, with tests and examples See: http://stackoverflow.com/questions/7004601/symfony2-testing-entity-validation-constraints