bulldog/id 问题修复 & 功能扩展

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

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

bulldog/id

最新稳定版本:v1.5.0

Composer 安装命令:

composer require bulldog/id

包简介

ID Generator

README 文档

README

Build Status PHP 7.2+ PHP version

A library for generating IDs.

Object ID

If your Object ID is long enough, it can be generated on multiple systems, without worrying about a collision. Using time-based buckets gives us locality for each new ID.

The first half of the ID is a bucket. The bucket is the difference between two unix timestamps. The first timestamp is the beginning of the current year, and the second timestamp is when the method is called. This is more efficient than only using the current timestamp. We will end up with more buckets this way.

The second half of the ID uses the random_bytes function. It is then safely encoded using base 64. We strip away any characters that are unsafe for URLs.

Usage

The example below generates 5,000 Object IDs.

<?php

require 'vendor/autoload.php';

use Bulldog\id\ObjectId;

$id = new ObjectId;

for($i=0; $i<5000; $i++) {
    var_dump($id->get(12));
}

Incremental ID

You can use multiple IDs to create a base64 encoded incremental ID. You may want to use the user's ID and another primary key from a relational database to create a unique incremental ID.

Usage

The example below will generate the same string each time.

<?php

require 'vendor/autoload.php';

use Bulldog\id\IncrementalId;

$id = new IncrementalId;

var_dump($id->create(4, 'dog', 9));
// Output: NAZG9nOQ

var_dump($id->get(4));
// Output: NAZG

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-04