aracoool/yii2-uuid 问题修复 & 功能扩展

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

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

aracoool/yii2-uuid

最新稳定版本:1.1.1

Composer 安装命令:

composer require aracoool/yii2-uuid

包简介

Yii 2 UUID Extension. A PHP 7.0+ library for generating RFC 4122 version 3, 4, and 5 universally unique identifiers (UUID).

README 文档

README

Latest Stable Version Packagist

Yii 2 UUID Extension. A PHP 7.0+ library for generating RFC 4122 version 3, 4, and 5 universally unique identifiers (UUID).

About

From Wikipedia:

The intent of UUIDs is to enable distributed systems to uniquely identify information without significant central coordination. In this context the word unique should be taken to mean "practically unique" rather than "guaranteed unique". Since the identifiers have a finite size, it is possible for two differing items to share the same identifier. The identifier size and generation process need to be selected so as to make this sufficiently improbable in practice. Anyone can create a UUID and use it to identify something with reasonable confidence that the same identifier will never be unintentionally created by anyone to identify something else. Information labeled with UUIDs can therefore be later combined into a single database without needing to resolve identifier (ID) conflicts.

Installation

The preferred method of installation is via Packagist and Composer. Run the following command to install the package and add it as a requirement to your project's composer.json:

composer require --prefer-dist aracoool/yii2-uuid

Usage

Behavior usage for V4

use \aracoool\yii2-uuid\UuidBehavior

/**
 * @return array
 */
public function behaviors()
{
    return [
        [
            'class' => UuidBehavior::class,
            'version' => Uuid::V4
        ],
        ...
    ];
}

Behavior usage for V3 and V5

use \aracoool\yii2-uuid\UuidBehavior

/**
 * @return array
 */
public function behaviors()
{
    return [
        [
            'class' => UuidBehavior::class,
            'version' => Uuid::V3, // Uuid::V5
            'namespace' => Uuid::NAMESPACE_NIL,
            'nameAttribute' => 'title' // Value of this attribute SHOULD be unique in your database
        ],
        ...
    ];
}
use \aracoool\yii2-uuid\Uuid

Uuid::v3(Uuid::NAMESPACE_URL, 'http://example.com/');
Uuid::v5(Uuid::NAMESPACE_DSN, 'www.google.com');
Uuid::v3(Uuid::NAMESPACE_OID, '1.3.6.1');
Uuid::v5(Uuid::NAMESPACE_X500, 'c=ca');
Uuid::v4();

Validator usage

use \aracoool\yii2-uuid\UuidValidator;

/**
 * @return array
 */
 public function rules()
 {
     return [
         ...
         ['attribute_id', UuidValidator::class],
         ...
     ];
 }

统计信息

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

GitHub 信息

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

其他信息

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