idoheo / string-generator
Random string generator library
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/idoheo/string-generator
Requires
- php: ~7.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ~2.3
- phpunit/phpunit: ~6.1
This package is not auto-updated.
Last update: 2025-10-21 22:08:58 UTC
README
Simple random string generator library. String generator is defined by interface \Idoheo\StringGenerator\StringGeneratorInterface.
Implemented 0-config string generators
The following string generators are pre implemented:
| Generator class | Generated string |
|---|---|
| Idoheo\StringGenerator\StringGenerator\AlnumCharStringGenerator | Alphanumeric string with upper and lowercase chars |
| Idoheo\StringGenerator\StringGenerator\HexStringGenerator | Hexadecimal string generator (lowercase chars) |
| Idoheo\StringGenerator\StringGenerator\NqCharStringGenerator | NQCHAR = %x21 / %x23-5B / %x5D-7E |
| Idoheo\StringGenerator\StringGenerator\NqsCharStringGenerator | NQSCHAR = %x20-21 / %x23-5B / %x5D-7E |
| Idoheo\StringGenerator\StringGenerator\VsCharStringGenerator | VSCHAR = %x20-7E |
Implemented configurable string generators
| Generator class | Generated string |
|---|---|
| Idoheo\StringGenerator\MappedStringGenerator | String of characters provided in array passed to constructor |
Writing own generator
To help writing your own generator, the following two abstract classes can be extended:
\Idoheo\StringGenerator\AbstractStringGenerator
For this class you have to implement ::executeStringGeneration() method. $length parameter is already checked to be non-negative integer value, so no checking (and exception throwing) from your part is needed in case of invalid $length specified.
\Idoheo\StringGenerator\SimplifiedAbstractStringGenerator
For this class you have to implement ::getCharacter() method to return next string character. As this is extending previous mentioned class, no checks on $length variable are needed.