germania-kg / random
1.0.6
2022-03-30 10:02 UTC
Requires
- php: ^5.6|^7.0
- paragonie/random-lib: ^2.0
- pimple/pimple: ^3.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^5.7|^6.0|^7.0
This package is auto-updated.
Last update: 2024-08-29 04:43:04 UTC
README
Pimple 服务提供者,用于从 ircmaxells 的 RandomLib 创建随机生成器
安装
$ composer require germania-kg/random
设置
<?php use Germania\Random\RandomServiceProvider; // A. Use with Slim or Pimple $app = new \Slim\App; $dic = $app->getContainer(); $dic = new Pimple\Container; // B. Register Service Provider. // Optionally pass length and strenth: $rsp = new RandomServiceProvider; $rsp = new RandomServiceProvider( 240, 5); $dic->register( $rsp );
服务
RandomGenerator
返回一个 RandomLib\Generator 实例。有关如何处理它的信息,请参阅 RandomLib 文档。
$generator = $dic['RandomGenerator']; $str = $generator->generateString(32, 'abcdef');
RandomGenerator.Callable
返回一个围绕 RandomLib\Generator 实例的可调用包装器,该实例可以创建任意长度的随机字符串。该可调用接受一个可选的字符串长度。
$random_callable = $dic['RandomGenerator.Callable']; $str = $random_callable(); // 256 characters $str = $random_callable( 256 ); // 256 chars $str = $random_callable( 64 ); // 64 chars.
RandomGenerator.Strength
返回用于创建 RandomLib\Generator 的 \SecurityLib\Strength 实例。
$strength = $dic['RandomGenerator.Strength'];
RandomGenerator.Length
返回生成的随机字符串的默认长度。
$length = $dic['RandomGenerator.Length'];
开发
$ git clone https://github.com/GermaniaKG/Random.git
$ cd Random
$ composer install
单元测试
可以将 phpunit.xml.dist
复制到 phpunit.xml
并根据您的需要进行调整,或者保持不变。运行 PhpUnit 测试或 composer 脚本,如下所示
$ composer test # or $ vendor/bin/phpunit