Download the PHP package inanepain/id-forge without Composer

On this page you can find all versions of the php package inanepain/id-forge. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package id-forge

= inanepain/id-forge image:./icon.png[title=inanepain/id-forge,25] :author: Philip Michael Raab :email: [email protected] :description: A lightweight & versatile library for generating and encoding unique identifiers. It provides fast, secure, and flexible solutions for modern applications. :keywords: inanepain, library, unique identifier, id generation, base32, base58, base64, nanoid, snowflakeid, uuid, ulid, php, encoding, cryptography :homepage: https://github.com/inanepain/id-forge :revnumber: 0.1.0 :revdate: 2025-10-29 :copyright: Unlicense :experimental: :hide-uri-scheme: :icons: font :source-highlighter: highlight.js :toc: left :sectanchors: :idprefix: topic- :idseparator: - :pkg-vendor: inanepain :pkg-name: id-forge :pkg-id: {pkg-vendor}/{pkg-name}

== image:./icon.png[title={pkg-id},25] {pkg-id}

{description}

TIP: All examples target PHP 8.2+ (the codebase is PHP 8.4-ready). Namespaces are rooted under Inane\IdForge.

<<<

:leveloffset: +1

= Install

.composer [source,shell,subs=attributes+]

composer require {pkg-id}

:leveloffset!:

<<<

== Quickstart

.Generate a few IDs [source,php]

use Inane\IdForge\IdGeneratorFactory; use Inane\IdForge\EncoderFactory;

$uuid = IdGeneratorFactory::createUUID()->generate(); $ulid = IdGeneratorFactory::createULID()->generate(); $nanoid = IdGeneratorFactory::createNanoid()->generate(); $snow = IdGeneratorFactory::createSnowflake(1, 2)->generate();

$base58 = EncoderFactory::createBase58(); $encoded = $base58->encode($ulid); $decoded = $base58->decode($encoded);

== Modules

:leveloffset: +1

= Encoders :author: Philip Michael Raab :email: [email protected] :experimental: :hide-uri-scheme: :icons: font :source-highlighter: highlight.js :sectnums: |,all| :toc: auto :sectanchors:

This module provides reversible string encoders that share a simple contract, EncoderInterface. Implementations cover Base32, Base58, and Base64 (including a URL-safe variant).

== Contracts and base classes

=== Inane\IdForge\Interface\EncoderInterface

Contract for reversible string encoders:

Implementations must be deterministic and satisfy decode(encode($x)) === $x for valid input. Invalid input should raise Inane\Stdlib\Exception\InvalidArgumentException (or a domain-specific exception).

=== Inane\IdForge\Encoder\AbstractEncoder

A small base class that stores an EncoderConfig and exposes helpers:

Concrete encoders (Base32/58/64) extend this class.

== Implementations

=== Base32

Namespace: Inane\IdForge\Encoder\Base32Encoder

.Usage [source,php]

use Inane\IdForge\EncoderFactory;

$base32 = EncoderFactory::createBase32(); $enc = $base32->encode("\x00\xFFHello"); $bin = $base32->decode($enc);

=== Base58

Namespace: Inane\IdForge\Encoder\Base58Encoder

.Usage [source,php]

use Inane\IdForge\EncoderFactory;

$base58 = EncoderFactory::createBase58(); $enc = $base58->encode("\0\0payload"); $bin = $base58->decode($enc);

=== Base64

Namespace: Inane\IdForge\Encoder\Base64Encoder

.Usage (URL-safe) [source,php]

use Inane\IdForge\EncoderFactory;

$base64 = EncoderFactory::createBase64(); $token = $base64->urlEncode(random_bytes(16)); $bytes = $base64->urlDecode($token);

== Configuration

Encoders accept Inane\IdForge\Config\EncoderConfig which holds:

Use EncoderFactory for sensible defaults or construct encoders manually with a custom alphabet.

== Exceptions

== See also

:leveloffset!:

<<<

:leveloffset: +1

= Generators :author: Philip Michael Raab :email: [email protected] :experimental: :hide-uri-scheme: :icons: font :source-highlighter: highlight.js :sectnums: |,all| :toc: auto :sectanchors:

IdForge includes several generators that implement a common contract, IdGeneratorInterface. Each generator focuses on a different trade-off: interoperability (UUID), sortability (ULID, Snowflake), or brevity and URL-friendliness (Nanoid).

== Contract and base class

=== Inane\IdForge\Interface\IdGeneratorInterface

Implementations should be fast, low-collision, and safe to use concurrently.

=== Inane\IdForge\Generator\AbstractIdGenerator

Provides helpers shared by all generators:

== Implementations

=== UUIDv4

Namespace: Inane\IdForge\Generator\UUIDGenerator

.Usage [source,php]

use Inane\IdForge\IdGeneratorFactory; use Inane\IdForge\EncoderFactory;

$uuid = IdGeneratorFactory::createUUID()->generate(); $base64 = EncoderFactory::createBase64(); $b64 = IdGeneratorFactory::createUUID()->toBase64($uuid, $base64); $uuid2 = IdGeneratorFactory::createUUID()->fromBase64($b64, $base64);

=== ULID

Namespace: Inane\IdForge\Generator\ULIDGenerator

.Usage [source,php]

use Inane\IdForge\IdGeneratorFactory;

$ulid = IdGeneratorFactory::createULID()->generate();

.Monotonic ULID [source,php]

use Inane\IdForge\Generator\ULIDGenerator; use Inane\IdForge\Config\EncoderConfig;

$mono = new ULIDGenerator(new EncoderConfig('0123456789ABCDEFGHJKMNPQRSTVWXYZ'), true); $a = $mono->generate(); $b = $mono->generate(); // guaranteed $a < $b when in same ms

=== Nanoid

Namespace: Inane\IdForge\Generator\NanoidGenerator

.Usage [source,php]

use Inane\IdForge\IdGeneratorFactory;

$id = IdGeneratorFactory::createNanoid()->generate();

=== Snowflake-like

Namespace: Inane\IdForge\Generator\SnowflakeIdGenerator

.Usage [source,php]

use Inane\IdForge\IdGeneratorFactory;

$gen = IdGeneratorFactory::createSnowflake(workerId: 1, datacenterId: 2); $id = $gen->generate();

== See also

:leveloffset!:

<<<

:leveloffset: +1

= Configuration :author: Philip Michael Raab :email: [email protected] :experimental: :hide-uri-scheme: :icons: font :source-highlighter: highlight.js :sectnums: |,all| :toc: auto :sectanchors:

This module documents the small configuration objects that accompany encoders and generators.

== EncoderConfig

Namespace: Inane\IdForge\Config\EncoderConfig

Holds the alphabet used by encoders and caches its length.

.Fields

.API

.Usage [source,php]

use Inane\IdForge\Config\EncoderConfig; use Inane\IdForge\Encoder\Base32Encoder;

$config = new EncoderConfig('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'); $encoder = new Base32Encoder($config);

== SnowflakeConfig

Namespace: Inane\IdForge\Config\SnowflakeConfig

Controls the epoch and bit allocations for Snowflake-like IDs.

.Fields

.API

.Usage [source,php]

use Inane\IdForge\Generator\SnowflakeIdGenerator; use Inane\IdForge\Config\SnowflakeConfig;

$config = new SnowflakeConfig(epoch: 1700000000000, workerIdBits: 6, datacenterIdBits: 4, sequenceBits: 12); $gen = new SnowflakeIdGenerator(workerId: 3, datacenterId: 1, config: $config); $id = $gen->generate();

== See also

:leveloffset!:

<<<

:leveloffset: +1

= Factories :author: Philip Michael Raab :email: [email protected] :experimental: :hide-uri-scheme: :icons: font :source-highlighter: highlight.js :sectnums: |,all| :toc: auto :sectanchors:

Factory helpers provide convenient, opinionated constructors for common encoders and generators.

== EncoderFactory

Namespace: Inane\IdForge\EncoderFactory

Creates encoder instances with sensible default alphabets.

.API

.Usage [source,php]

use Inane\IdForge\EncoderFactory;

$base32 = EncoderFactory::createBase32(); $base58 = EncoderFactory::createBase58(); $base64 = EncoderFactory::createBase64();

== IdGeneratorFactory

Namespace: Inane\IdForge\IdGeneratorFactory

Creates generator instances with defaults and safe validation where applicable.

.API

.Usage [source,php]

use Inane\IdForge\IdGeneratorFactory;

$uuid = IdGeneratorFactory::createUUID()->generate(); $ulid = IdGeneratorFactory::createULID()->generate(); $nanoid = IdGeneratorFactory::createNanoid()->generate(); $snow = IdGeneratorFactory::createSnowflake(workerId: 1, datacenterId: 2)->generate();

== See also

:leveloffset!:

<<<

:leveloffset: +1

= Example :author: Philip Michael Raab :email: [email protected] :experimental: :hide-uri-scheme: :icons: font :source-highlighter: highlight.js :sectnums: |,all| :toc: auto :sectanchors:

.Some examples [source,php]

use Inane\IdForge\Config\EncoderConfig; use Inane\IdForge\Config\SnowflakeConfig; use Inane\IdForge\Encoder\AbstractEncoder; use Inane\IdForge\EncoderFactory; use Inane\IdForge\Generator\AbstractIdGenerator; use Inane\IdForge\IdGeneratorFactory;

// Example usage try { // Create encoders via factory $base32 = EncoderFactory::createBase32(); $base58 = EncoderFactory::createBase58(); $base64 = EncoderFactory::createBase64();

// Create ID generators via factory
$nanoid = IdGeneratorFactory::createNanoid();
$snowflake = IdGeneratorFactory::createSnowflake(1, 1);
$uuid = IdGeneratorFactory::createUUID();
$ulid = IdGeneratorFactory::createULID();

// Base32
$base32Encoded = $base32->encode('Hello');
echo "Base32 Encoded: $base32Encoded\n";
echo 'Base32 Decoded: ' . $base32->decode($base32Encoded) . "\n";
echo PHP_EOL;

// Base58
$base58Encoded = $base58->encode('Hello');
echo "Base58 Encoded: $base58Encoded\n";
echo 'Base58 Decoded: ' . $base58->decode($base58Encoded) . "\n";
echo PHP_EOL;

// Base64
$base64Encoded = $base64->urlEncode('Hello');
echo "Base64 URL Encoded: $base64Encoded\n";
echo 'Base64 URL Decoded: ' . $base64->urlDecode($base64Encoded) . "\n";
echo PHP_EOL;

// Nanoid
echo 'Nanoid: ' . $nanoid->generate() . "\n";
echo PHP_EOL;

// Snowflake ID
$snowflakeId = $snowflake->generate();
echo "Snowflake ID: $snowflakeId\n";
echo 'Snowflake ID (Base58): ' . $snowflake->toEncoded($base58) . "\n";
echo PHP_EOL;

// UUID
$uuidValue = $uuid->generate();
echo "UUID: $uuidValue\n";
$uuidBase64 = $uuid->toBase64($uuidValue, $base64);
echo "UUID Base64: $uuidBase64\n";
echo 'UUID from Base64: ' . $uuid->fromBase64($uuidBase64, $base64) . "\n";
echo PHP_EOL;

// ULID
$ulidValue = $ulid->generate();
echo "ULID: $ulidValue\n";
echo 'ULID Timestamp: ' . $ulid->decodeTimestamp($ulidValue) . "\n";
echo 'ULID Base32: ' . $ulid->toEncoded($base32) . "\n";
echo PHP_EOL;

// ULID
$ulidValue = $ulid->generate(1761168799791);
echo "ULID 2: $ulidValue\n";
echo 'ULID 2 Timestamp: ' . $ulid->decodeTimestamp($ulidValue) . "\n";
echo 'ULID 2 Base32: ' . $ulid->toEncoded($base32) . "\n";

} catch (Exception $e) { echo 'Error: ' . $e->getMessage() . "\n"; }

// Add a New Encoder: class Base16Encoder extends AbstractEncoder { public function construct() { parent::construct(new EncoderConfig('0123456789ABCDEF')); }

public function encode(string $data): string {
    return strtoupper(bin2hex($data));
}

public function decode(string $data): string {
    return hex2bin($data);
}

}

class Encoder2Factory { public static function createBase16(): Base16Encoder { return new Base16Encoder(); } }

$base16 = Encoder2Factory::createBase16()->encode('Hello'); $text = Encoder2Factory::createBase16()->decode($base16); $line("Base16:encoded: $base16"); $line("Base16:decoded: $text"); // EncoderFactory::createBase16 = fn() => new Base16Encoder();

// Add a New ID Generator: class CustomIdGenerator extends AbstractIdGenerator { public function generate(): string { $timestamp = $this->getTimestamp(); $random = $this->getRandomBytes(8); return bin2hex($timestamp . $random); } }

class IdGenerator2Factory { public static function createCustomId(): CustomIdGenerator { return new CustomIdGenerator(); } }

$customId = IdGenerator2Factory::createCustomId()->generate(); $line("CustomID: $customId");

// IdGeneratorFactory::createCustomId = fn() => new CustomIdGenerator();

// Customize Snowflake Configuration: $customConfig = new SnowflakeConfig(1640995200000, 4, 4, 10); // Custom epoch, fewer bits $snowflake = IdGeneratorFactory::createSnowflake(1, 1, $customConfig);

// Custom Alphabet for Nanoid: $nanoid = IdGeneratorFactory::createNanoid('0123456789abcdef', 12); // Hex-only, shorter length

:leveloffset!:

<<<

:leveloffset: +1

= UUIDTool

Quickly create UUIDs.

== Examples

[source,php]

<?php

declare(strict_types = 1);

require_once '/Users/philip/Sites/inane-fw/vendor/autoload.php';

use Inane\IdForge\UUIDTool; use Inane\Stdlib\Options;

$namespace = '65eeece0-a2e2-11f0-8ead-a343ec01a981'; $name = 'inane-fw';

$ids = new Options(); $ids->namespace = $namespace; $ids->name = $name; $ids->mac = UUIDTool::getMacAddress(); $ids->v1 = ['UUID'=>UUIDTool::v1(), 'version' => null]; $ids->v3 = ['UUID'=>UUIDTool::v3($namespace, $name), 'version' => null]; $ids->v4 = ['UUID'=>UUIDTool::v4(), 'version' => null]; $ids->v5 = ['UUID'=>UUIDTool::v5($namespace, $name), 'version' => null]; $ids->v7 = ['UUID'=>UUIDTool::v7(), 'version' => null]; $ids->v1->version = UUIDTool::getVersion($ids->v1->UUID); $ids->v3->version = UUIDTool::getVersion($ids->v3->UUID); $ids->v4->version = UUIDTool::getVersion($ids->v4->UUID); $ids->v5->version = UUIDTool::getVersion($ids->v5->UUID); $ids->v7->version = UUIDTool::getVersion($ids->v7->UUID);

dd($ids);

:leveloffset!:

<<<

== Error handling

== When to use which generator


All versions of id-forge with dependencies

PHP Build Version
Package Version
Requires php Version >=8.4
inanepain/stdlib Version >=0.7.1 || dev-master || dev-develop
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package inanepain/id-forge contains the following files

Loading the files please wait ...