marvin255/random-string-generator

symfony 的随机字符串生成器。

v3.2.2 2024-06-08 12:53 UTC

This package is auto-updated.

Last update: 2024-09-08 13:15:22 UTC


README

Latest Stable Version Total Downloads License Build Status

安装

通过 composer 安装包

composer req marvin255/random-string-generator

它将自动配置。

使用方法

通过依赖注入将生成器注入到服务或控制器中

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

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

使用生成器的方法之一

$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

模拟字符串进行测试

可以将扩展配置为在测试环境中返回模拟字符串。

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

所有方法调用都将返回 mock_string