marvin255/random-string-generator

Random string generator for symfony.

Installs: 1 877

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 4

Forks: 1

Open Issues: 0

Type:symfony-bundle

v3.2.1 2024-02-24 21:38 UTC

This package is auto-updated.

Last update: 2024-03-24 21:45:18 UTC


README

Latest Stable Version Total Downloads License Build Status

Installation

Install package via composer:

composer req marvin255/random-string-generator

It will be configured automatically.

Usage

Inject the generator to a service or a controller via DI:

use Marvin255\RandomStringGenerator\Generator\RandomStringGenerator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class SiteController extends AbstractController
{
    public function __construct(private readonly RandomStringGenerator $randomStringGenerator)
    {
    }
}

Use one of the generators methods:

$this->randomStringGenerator->alphanumeric(10);  // 10 symbols of latin alphabet or digits
$this->randomStringGenerator->alpha(10);         // 10 symbols of latin alphabet
$this->randomStringGenerator->numeric(10);       // 10 symbols of digits
$this->randomStringGenerator->password(10);      // 10 symbols that can be used as password
$this->randomStringGenerator->string(10, 'qwe'); // 10 symbols of provided vocabulary

Mock strings for testing

Bundle can be configured to return a mock string in the test environment.

# config/packages/test/marvin255_random_string_generator.yaml
marvin255_random_string_generator:
    dummy: true
    dummy_string: mock_string

All methods calls will return mock_string.