- 7.2
- 7.3
- 7.4
- 8.0
- For PHP 5.5 use the 0.0.5 branch releases
- For PHP 5.6 use the 1.1.x branch releases
- For PHP 7.1 use the 2.1.0 release
- For PHP 7.2 use the 2.4.x release
- For PHP 8.0+ use the 2.5.x release
A wrapper package for easy use of the excellent Ramsey\UUID package. Currently the package generates a version 4 UUID according to RFC 4122.
This package provides 2 methods of generating a UUID.
- Static Facade UUID with a generate method.
- AssignUUID Trait that defaults to a class variable of
$id
or accepts the string name of a class variable to assign the uuid to.
use eig\UUID;
class Example {
protected $id;
public function __construct()
{
$this->id = UUID::generate();
}
}
use eig\UUID\AssignUUID;
class Example
{
use AssignUUID;
/**
* @var
*/
protected $id;
/**
* Example constructor.
*/
public function __construct ()
{
$this->assignUUID();
}
/**
* getID
* @return mixed
*/
public function getID()
{
return $this->id;
}
}
Or with a class variable other than $id
use eig\UUID\AssignUUID;
/**
* Class AlternateFieldExample
* @package eig\UUID
* @license MIT
* @author James Johnson
* @author Excellent InGenuity LLC
*/
class AlternateFieldExample
{
use AssignUUID;
/**
* @var
*/
protected $alternateID;
/**
* AlternateFieldExample constructor.
*/
public function __construct ()
{
$this->assignUUID('alternateID');
}
/**
* getAlternateID
* @return mixed
*/
public function getAlternateID()
{
return $this->alternateID;
}
}