定制 not-empty/ulid-php-lib 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

not-empty/ulid-php-lib

最新稳定版本:8.0.0

Composer 安装命令:

composer require not-empty/ulid-php-lib

包简介

PHP Universally Unique Lexicographically Sortable Identifier (ULID)

README 文档

README

Latest Version codecov CI Build Downloads Old Downloads PRs Welcome Packagist License (custom server)

PHP library to create a ULID unique identifier value

Installation

Release 8.0.0 Requires PHP 8.4

Release 7.0.0 Requires PHP 8.3

Release 6.0.0 Requires PHP 8.2

Release 5.0.0 Requires PHP 8.1

Release 4.0.0 Requires PHP 7.4

Release 3.0.0 Requires PHP 7.3

Release 2.0.0 Requires PHP 7.2

Release 1.0.0 Requires PHP 7.1

The recommended way to install is through Composer.

composer require not-empty/ulid-php-lib

Usage

Generate an Ulid

use Ulid\Ulid;
$ulid = new Ulid();
$ulidFromNow = $ulid->generate();
echo $ulidFromNow;

Generate an Ulid from a timestamp

use Ulid\Ulid;
$ulid = new Ulid();
$ulidFromTime = $ulid->generate(1585083964945);
echo $ulidFromTime;

Validates if is a valid Ulid from a string

use Ulid\Ulid;
$ulid = new Ulid();
$invalid = $ulid->isValidFormat('1585083964945');
var_dump($invalid)

Recover timestamp from Ulid

use Ulid\Ulid;
$ulid = new Ulid();
$timeFromUlid = $ulid->getTimeFromUlid('01E48SD97BMWHAW82D229T0C7K');
echo $timeFromUlid;

Recover date from Ulid

use Ulid\Ulid;
$ulid = new Ulid();
$dateFromUlid = $ulid->getDateFromUlid('01E48SD97BMWHAW82D229T0C7K');
echo $dateFromUlid;

Recover randomness from Ulid

use Ulid\Ulid;
$ulid = new Ulid();
$randomnessFromUlid = $ulid->getRandomnessFromString('01E475VQGHNW990PVHXFDT4C6R');
echo $randomnessFromUlid;

if you want an environment to run or test it, you can build and install dependences like this

docker build --build-arg PHP_VERSION=8.4-cli -t not-empty/ulid-php-lib:php84 -f contrib/Dockerfile .

Access the container

docker run -v ${PWD}/:/var/www/html -it not-empty/ulid-php-lib:php84 bash

Verify if all dependencies is installed

composer install --no-dev --prefer-dist

and run

php sample/ulid-sample.php

Development

Want to contribute? Great!

The project using a simple code. Make a change in your file and be careful with your updates! Any new code will only be accepted with all validations.

To ensure that the entire project is fine:

First you need to building a correct environment to install all dependences

docker build --build-arg PHP_VERSION=8.4-cli -t not-empty/ulid-php-lib:php84 -f contrib/Dockerfile .

Access the container

docker run --name ulid-php-lib -v ${PWD}/:/var/www/html -it not-empty/ulid-php-lib:php84 bash

Install all dependences

composer install --dev --prefer-dist

Run all validations

composer check

Not Empty Foundation - Free codes, full minds

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-only
  • 更新时间: 2023-10-16