marvin255 / random-string-generator
Random string generator for symfony.
Installs: 2 827
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.1
- symfony/framework-bundle: ^6.0|^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- infection/infection: ^0.27.0
- phpunit/phpunit: ^10.0
- symfony/phpunit-bridge: ^7.0
- vimeo/psalm: ^5.0
README
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
.