Skip to content

sudiptpa/guid

Repository files navigation

GUID (Globally Unique Identifier) for PHP

A minimal, dependency-free GUID (Globally Unique Identifier) generator for PHP with a tiny runtime footprint. Frequently also called UUIDs (Universally Unique Identifiers).

CI Latest Version Downloads License PHP Version


Sponsor

If this package has been useful to you, GitHub Sponsors is a simple way to support ongoing maintenance, improvements, and future releases.

Requirements

  • PHP 8.2+

Compatibility

  • Supported and CI-tested on PHP 8.2, 8.3, 8.4, and 8.5.
  • Need legacy PHP support below 8.2? Use sudiptpa/guid:^2.0.

Installation

composer require sudiptpa/guid

Usage

Basic usage

<?php

declare(strict_types=1);

use Sujip\Guid\Guid;

$guid = new Guid();

echo $guid->create();
// Example: 2b23924f-0eaa-4133-848e-7ce1edeca8c9

Global helper

<?php

declare(strict_types=1);

echo guid();
// Example: 2b23924f-0eaa-4133-848e-7ce1edeca8c9

echo guid(false);
// Example: {2b23924f-0eaa-4133-848e-7ce1edeca8c9}

Extending generation behavior

Default usage is unchanged. If needed, provide your own generator:

<?php

declare(strict_types=1);

use Sujip\Guid\GeneratorInterface;
use Sujip\Guid\Guid;

final class CustomGenerator implements GeneratorInterface
{
    public function generate(bool $trim = true): string
    {
        return $trim ? 'custom-guid' : '{custom-guid}';
    }
}

$guid = new Guid(new CustomGenerator());

echo $guid->create(); // custom-guid

Public API stability

The package preserves the existing public behavior:

  • Sujip\Guid\Guid::create(bool $trim = true): string
  • guid(bool $trim = true): string

No runtime dependencies are required, and default usage stays a single class or helper call.

Development

composer install
composer lint
composer stan
composer test

Changelog

See CHANGELOG.md.

Contributing

See CONTRIBUTING.md.

Maintainer notes

See MAINTAINERS.md.

License

MIT. See LICENSE.

About

Lightweight, standalone GUID (Globally Unique Identifier) generator for PHP 8.2+ with a tiny API, zero runtime dependencies, and predictable UUID-like output.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages