seyfahni/haikunator
最新稳定版本:1.0.1
Composer 安装命令:
composer require seyfahni/haikunator
包简介
Generate random words or phrases usable as IDs.
README 文档
README
This project was inspired by HaikunatorPHP and Jitsi.
It allows generation of human-friendly IDs.
Installation
composer require seyfahni/haikunator
Usage
As a consumer you can expect an Haikunator instance to be injected into your class.
To generate an id just call the haikunate() method:
use seyfahni\Haikunator\Haikunator; /** @var Haikunator $haikunator */ $haikunator->haikunate();
Creating an instance via Haikunators
The Haikunators helper class contains methods for easy creation of common Haikunators:
use seyfahni\Haikunator\Haikunators; $atroxHaikunator = Haikunators::atroxHaikunator(); $jitsiHaikunator = Haikunators::jitsiHaikunator();
Creating a Haikunator by hand
There are multiple implementation of the Haikunator interface provided.
Usually you want to put a combination of WordListHaikunators and CharactersHaikunator into one AppendingHaikunator.
use seyfahni\Haikunator\AppendingHaikunator; use seyfahni\Haikunator\CharactersHaikunator; use seyfahni\Haikunator\ConstantHaikunator; use seyfahni\Haikunator\MtRandIntegerGenerator; use seyfahni\Haikunator\WordListHaikunator; $numberGenerator = new MtRandIntegerGenerator(); # Generate IDs like my-useful-aHt $haikunator = new AppendingHaikunator([ new ConstantHaikunator('my'), new WordListHaikunator($numberGenerator, ['fancy', 'useful', 'modular']), new CharactersHaikunator($numberGenerator, 'Haikunator', 3), ], '-' );
The IntegerGenerator interface is used by some Haikunator implementations so that
any kind of number generation can be used via adapter implementation.
Extension
Use your own generation logic by implementing the Haikunator interface and using an instance of it via "creation by hand".
统计信息
- 总下载量: 157
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-01-19