germania-kg/random

1.0.6 2022-03-30 10:02 UTC

This package is auto-updated.

Last update: 2024-10-29 05:16:29 UTC


README

Pimple Service Provider for creating a Random Generator from ircmaxells' RandomLib

Packagist PHP version Build Status Scrutinizer Code Quality Code Coverage Build Status

Installation

$ composer require germania-kg/random

Setup

<?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  );

Services

RandomGenerator

Returns a RandomLib\Generator instance. See RandomLib docs on how to deal with it.

$generator = $dic['RandomGenerator'];
$str = $generator->generateString(32, 'abcdef');

RandomGenerator.Callable

Returns a Callable wrapper around the RandomLib\Generator instance which creates a random string af arbitrary length. The callable accepts an optional string length.

$random_callable = $dic['RandomGenerator.Callable'];
$str = $random_callable(); // 256 characters
$str = $random_callable( 256 ); // 256 chars
$str = $random_callable( 64 ); // 64 chars.

RandomGenerator.Strength

Returns the \SecurityLib\Strength instance used for creating the RandomLib\Generator

$strength = $dic['RandomGenerator.Strength'];

RandomGenerator.Length

Returns the default length of generated random strings.

$length = $dic['RandomGenerator.Length'];

Development

$ git clone https://github.com/GermaniaKG/Random.git
$ cd Random
$ composer install

Unit tests

Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:

$ composer test
# or
$ vendor/bin/phpunit