### Install Nanoid-php via Composer Source: https://github.com/hidehalo/nanoid-php/blob/2.x/README.md Instructions to install the nanoid-php library using Composer. This is the standard method for adding PHP packages to your project. ```bash composer require hidehalo/nanoid-php ``` -------------------------------- ### Running Tests Source: https://github.com/hidehalo/nanoid-php/blob/2.x/CONTRIBUTING.md Executes the project's test suite using Composer. Ensure you have dependencies installed via `composer install` before running tests. ```bash $ composer test ``` -------------------------------- ### Generate Default and Dynamic IDs Source: https://github.com/hidehalo/nanoid-php/blob/2.x/README.md Demonstrates generating unique IDs using the nanoid-php client. It shows how to use the default random generator and a more secure dynamic mode for ID generation. Requires the Hidehalo\Nanoid\Client class. ```php use Hidehalo\Nanoid\Client; use Hidehalo\Nanoid\GeneratorInterface; $client = new Client(); # default random generator echo $client->generateId($size = 21); # more safer random generator echo $client->generateId($size = 21, $mode = Client::MODE_DYNAMIC); ``` -------------------------------- ### Generate ID with Custom Alphabet and Size Source: https://github.com/hidehalo/nanoid-php/blob/2.x/README.md Shows how to generate an ID with a custom alphabet and a specified size using the `formattedId` method. The alphabet must contain 256 symbols or less for security guarantees. ```php echo $client->formattedId($alphabet = '0123456789abcdefg', $size = 21); ``` -------------------------------- ### Generate ID with Custom Random Bytes Generator Source: https://github.com/hidehalo/nanoid-php/blob/2.x/README.md Illustrates generating an ID using a custom random bytes generator by implementing the `GeneratorInterface`. This allows for custom random number generation logic, useful for specific environments or testing. Requires PHP 7.0+ for anonymous classes. ```php # PS: anonymous class is new feature when PHP_VERSION >= 7.0 echo $client->formattedId($alphabet = '0123456789abcdefg', $size = 21, new class implements GeneratorInterface { /** * @inheritDoc */ public function random($size) { //TODO: implemenation ... } }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.