Skip to content

excellentingenuity/UUID

Repository files navigation

UUID

Build Status Latest Stable Version Coverage Status License StyleCI Total Downloads Latest Unstable Version

Supported PHP Versions

  • 7.2
  • 7.3
  • 7.4
  • 8.0

Version Support

Description

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.

  1. Static Facade UUID with a generate method.
  2. AssignUUID Trait that defaults to a class variable of $id or accepts the string name of a class variable to assign the uuid to.

Static Method Example

use eig\UUID;

class Example {
    
    protected $id;
    
    public function __construct()
    {
        $this->id = UUID::generate();
    }
}

AssignUUID Trait Example

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;
    }
}

About

A wrapper package for easy use of the excellent Ramsey\UUID package. Currently the package generates a version 4 UUID according to RFC 4122.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages