An open API service indexing awesome lists of open source software.

https://github.com/projectsaturnstudios/quickuuid

Simple helper functions to easily generate UUIDs (v4 and v5).
https://github.com/projectsaturnstudios/quickuuid

Last synced: 6 months ago
JSON representation

Simple helper functions to easily generate UUIDs (v4 and v5).

Awesome Lists containing this project

README

          

# ProjectSaturnStudios/QuickUUID

A simple PHP library providing helper functions to easily generate version 4 (random) and version 5 (name-based, SHA-1) UUIDs. It leverages the robust `ramsey/uuid` package under the hood.

## Features

- Generate UUIDv4.
- Generate UUIDv5 with a specified name and an optional namespace.
- A primary helper `new_uuid()` that intelligently calls either v4 or v5 generation based on provided arguments.
- Configurable default namespace for UUIDv5 generation.

## Installation

Install the package via Composer:

```bash
composer require projectsaturnstudios/quickuuid
```

## Basic Usage

```php

```

### UUIDv5 Namespace Configuration

The `new_uuid5()` and `new_uuid()` (when generating a v5 UUID) functions use a default namespace. This default is `Ramsey\Uuid\Uuid::NAMESPACE_DNS`.

You can change this application-wide default by defining the `QUICKUUID_DEFAULT_V5_NAMESPACE` constant *before* the `quickuuid/src/Helpers/helpers.php` file is loaded by Composer. Make sure the value you define is a valid UUID string.

Example (e.g., in your `bootstrap/app.php` or an early Composer autoloaded file):

```php
if (!defined('QUICKUUID_DEFAULT_V5_NAMESPACE')) {
define('QUICKUUID_DEFAULT_V5_NAMESPACE', 'YOUR-OWN-DEFAULT-NAMESPACE-UUID'); // Replace with your actual UUID
}

// Composer will then load quickuuid's helpers, which will use this constant.
```

## Dependencies

- PHP ^8.2
- `ramsey/uuid`: ^4.7

## Running Quality Assurance

This package uses PHPUnit for tests and PHPStan for static analysis.

To run tests:
```bash
composer test
```

To run static analysis:
```bash
composer analyse
```

## License

This package is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.

## Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue.