thamtech/yii2-uuid
最新稳定版本:v1.2.2
Composer 安装命令:
composer require thamtech/yii2-uuid
包简介
Yii 2 UUID Helper
README 文档
README
UUID Helper and validator for Yii 2.
This library interfaces with ramsey/uuid to generate universally unique identifiers.
For license information check the LICENSE-file.
Installation
The preferred way to install this extensions is through composer.
Either run
php composer.phar require --prefer-dist thamtech/yii2-uuid
or add
"thamtech/yii2-uuid": "*"
to the require section of your composer.json file.
Usage
New UUID
Generate a new UUID (version 4 by default):
$uuid = \thamtech\uuid\helpers\UuidHelper::uuid();
Ad-Hoc Validation
Validate that a string is formatted in the canonical format using hexadecimal text with inserted hyphen characters (case insensitive):
$uuid = 'de305d54-75b4-431b-adb2-eb6b9e546014'; $isValid = \thamtech\uuid\helpers\UuidHelper::isValid($uuid); // true $uuid = 'not-a-uuid'; $isValid = \thamtech\uuid\helpers\UuidHelper::isValid($uuid); // false // or using the Validator class directly $validator = new \thamtech\uuid\validators\UuidValidator(); if ($validator->validate($uuid, $error)) { // valid } else { // not valid echo $error }
Or you can include the use lines, especially if you will be making multiple
uuid calls within a file:
use thamtech\uuid\helpers\UuidHelper; use thamtech\uuid\helpers\UuidValidator; // ... $uuid = 'de305d54-75b4-431b-adb2-eb6b9e546014'; $isValid = UuidHelper::isValid($uuid); // true $uuid = 'not-a-uuid'; $isValid = UuidHelper::isValid($uuid); // false // or using the Validator class directly $validator = new UuidValidator(); if ($validator->validate($uuid, $error)) { // valid } else { // not valid echo $error }
Field Validation
Incorporate this same validation into your model:
public function rules() { return [ [['uuid'], 'thamtech\uuid\validators\UuidValidator'], ]; }
See Also
统计信息
- 总下载量: 327.69k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 35
- 点击次数: 1
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2015-10-08