iliain/php-zoo-ids 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

iliain/php-zoo-ids

最新稳定版本:2.0.0

Composer 安装命令:

composer require iliain/php-zoo-ids

包简介

A PHP version of bryanmylee's zoo-ids, originally written in JavaScript

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

A PHP version of bryanmylee's zoo-ids, originally written in JavaScript, which was in turn inspired by the URL ID's of gfycat.com. For a frontend or backend that uses JavaScript, I highly recommend you use their package!

Generate predictable and unique identifiers composed of adjectives and animal names, with the ability to seed the random identifiers.

Range of IDs

Currently, there are 1347 adjectives and 221 animals. The more adjectives used, the more possible combinations of IDs available.

For a quick reference, with 2 adjectives used, there are 400,984,389 possible unique IDs.

With 3 adjectives, there are 540,125,971,983 possible unique IDs.

Installation

$ composer require iliain/php-zoo-ids

Usage

Examples

use Iliain\ZooIDs\UsernameRandomizer;

$randomizer = new UsernameRandomizer();
$randomizer->generateID('short seed'); // KnobbyNauticalKingfisher

// Defaults to the current time if seed is null.
$randomizer->generateID(null, 2, '🍓', 'lowercase'); // enchanted🍓narrow🍓wallaby

If you want to control the list of Nouns and Adjectives, you can provide your own:

$randomizer = new UsernameRandomizer(['Jumping','Flying','Running','Waving'], ['Rock', 'Paper', 'Scissors']);
$randomizer->generateID(); // JumpingRunningScissors

$randomizer->setAdjectives(['Diving','Walking','Spinning']);
$randomizer->generateID(); // WalkingDivingScissors

$randomizer->setNouns(['Koala', 'Dog']);
$randomizer->generateID(); // WalkingDivingKoala

Documentation

new UsernameRandomizer($adjectives, $nouns)

adjectives: array

An array of adjectives to use in generation. Defaults to preprovided list if none are specified.

nouns: array

An array of nouns to use in generation. Defaults to preprovided list if none are specified.

generateID($seed, $numAdjectives, $delimiter, $caseStyle)

seed: string|int

The seed used to generate the id. This allows us to generate predictable, but random and unique identifiers.

Defaults to the current time.

numAdjectives: int

The number of adjectives to use in the identifier.

Defaults to 2.

delimiter: string

The delimiter used between words. The delimiter will also be used between multi-word adjectives.

Defaults to ''.

caseStyle: string

The case style for the words. Possible options are 'titlecase', 'camelcase', 'uppercase', 'lowercase', and 'togglecase'.

generateID($seed, $numAdjectives, $delimiter, 'titlecase'); // FineAntiqueElk

generateID($seed, $numAdjectives, $delimiter, 'camelcase'); // pertinentPoshGoldfinch

generateID($seed, $numAdjectives, $delimiter, 'uppercase'); // PIERCINGRESPONSIBLECAMEL

generateID($seed, $numAdjectives, $delimiter, 'lowercase'); // imaginarywingedsalamander

generateID($seed, $numAdjectives, $delimiter, 'togglecase'); // sTuNnInGdEsCrIpTiVepEaFoWl

Defaults to 'titlecase'.

Credits

All credit goes to Bryan Lee and his zoo-ids package. I wanted a version of this to use in PHP (username generation was handled by a PHP CMS), and converted the majority of his existing code to that format. Currently lacking some of his original features, such as the ability to use objects as seeds.

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2022-11-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固