https://github.com/devuri/uuid-generator
The UUIDGenerator class is a secure and efficient way to generate UUIDs (Universally Unique Identifiers) in PHP. It generates UUIDs according to the RFC 4122 standard, which ensures that the UUIDs are unique across time and space.
https://github.com/devuri/uuid-generator
Last synced: 11 months ago
JSON representation
The UUIDGenerator class is a secure and efficient way to generate UUIDs (Universally Unique Identifiers) in PHP. It generates UUIDs according to the RFC 4122 standard, which ensures that the UUIDs are unique across time and space.
- Host: GitHub
- URL: https://github.com/devuri/uuid-generator
- Owner: devuri
- License: mit
- Created: 2023-03-04T13:25:06.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-04T14:08:29.000Z (almost 3 years ago)
- Last Synced: 2024-04-25T00:56:01.258Z (almost 2 years ago)
- Language: PHP
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
UUIDGenerator
=============
The `UUIDGenerator` class is a secure and efficient way to generate UUIDs (Universally Unique Identifiers) in PHP. It generates UUIDs according to the RFC 4122 standard, which ensures that the UUIDs are unique across time and space.
### Installation
You can install the `UUIDGenerator` class using Composer. Run the following command in your terminal:
composer require devuri/uuid-generator
Alternatively, you can manually include the `UUIDGenerator` class in your PHP project.
### Usage
To use the `UUIDGenerator` class, first import the class using the `use` keyword:
```php
use Devuri\UUIDGenerator\UUIDGenerator;
```
Then, create a new instance of the `UUIDGenerator` class:
```php
$uuidGenerator = new UUIDGenerator();
```
You can optionally specify the version and variant of the UUID you want to generate. The version determines the layout of the UUID, while the variant determines the encoding of the UUID. The default version is 4 (random), and the default variant is the RFC 4122 variant.
```php
$uuidGenerator = new UUIDGenerator(1, 0x80);
```
To generate a new UUID, call the `generateUUID()` method:
```php
$uuid = $uuidGenerator->generateUUID();
```
The generateUUID() method returns a string in the following format:
```shell
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
```
Where:
* `**x**` is a hexadecimal digit **(0-9, a-f)**
* `**M**` is the version number **(1-5)**
* **`N`** is the variant number **(8, 9, a, b)**
### Example
Here's an example of how to use the `UUIDGenerator` class to generate a new UUID:
```php
use Devuri\UUIDGenerator\UUIDGenerator;
$uuidGenerator = new UUIDGenerator();
$uuid = $uuidGenerator->generateUUID();
echo $uuid;
```
This code creates a new instance of the `UUIDGenerator` class, generates a new UUID, and then prints the UUID to the screen.
### Security
The `UUIDGenerator` class uses a secure and efficient method to generate UUIDs. It generates random bytes using the `random_bytes()` function, which is a cryptographically secure random number generator. It then sets the version and variant bits according to the RFC 4122 standard.
### License
The `UUIDGenerator` class is open-source software licensed under the MIT License. See the `LICENSE` file for more information.