Skip to content

Commit

Permalink
Merge pull request #7 from infocyph/feature/update
Browse files Browse the repository at this point in the history
Feature/update
  • Loading branch information
abmmhasan authored May 5, 2024
2 parents 1a4d2ad + 92a4eca commit 32006cc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
"description": "UUID (RFC 4122 + Unofficial/Draft), ULID, Snowflake ID, Sonyflake ID, TBSL (library exclusive) generator!",
"type": "library",
"license": "MIT",
"keywords": [
"uuid",
"ulid",
"snowflake",
"sonyflake",
"tbsl",
"id",
"key",
"unique"
],
"authors": [
{
"name": "abmmhasan",
Expand Down
2 changes: 1 addition & 1 deletion src/ULID.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ULID


/**
* Generates a ULID (Universally Unique Lexicographically Identifier).
* Generates a ULID (Universally Unique Lexicographically Sortable Identifier).
*
* @param DateTimeInterface|null $dateTime
* @return string
Expand Down
32 changes: 18 additions & 14 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Infocyph\UID;

use DateTimeInterface;
use Exception;
use Infocyph\UID\Exceptions\FileLockException;
use Infocyph\UID\Exceptions\SnowflakeException;
use Infocyph\UID\Exceptions\SonyflakeException;

Expand All @@ -24,14 +26,14 @@ function uuid1(string $node = null): string
/**
* Generate a Version 3 UUID.
*
* @param string $string The string to generate the UUID from.
* @param string $namespace The namespace to use for the UUID generation.
* @param string $string The string to generate the UUID from.
* @return string The generated UUID.
* @throws Exception|Exceptions\UUIDException
*/
function uuid3(string $string, string $namespace): string
function uuid3(string $namespace, string $string): string
{
return UUID::v3($string, $namespace);
return UUID::v3($namespace, $string);
}
}

Expand All @@ -50,16 +52,16 @@ function uuid4(): string

if (!function_exists('Infocyph\UID\uuid5')) {
/**
* Generates a version 5 UUID for a given string using the specified namespace.
* Generate a Version 5 UUID.
*
* @param string $string The string to generate the UUID from.
* @param string $namespace The namespace to use for the UUID generation.
* @param string $string The string to generate the UUID from.
* @return string The generated UUID.
* @throws Exceptions\UUIDException
* @throws Exception|Exceptions\UUIDException
*/
function uuid5(string $string, string $namespace): string
function uuid5(string $namespace, string $string): string
{
return UUID::v5($string, $namespace);
return UUID::v5($namespace, $string);
}
}

Expand All @@ -81,13 +83,14 @@ function uuid6(string $node = null): string
/**
* Generates a version 7 UUID.
*
* @param DateTimeInterface|null $dateTime An optional DateTimeInterface object to create the UUID.
* @param string|null $node The node identifier. Defaults to null.
* @return string
* @throws Exception
*/
function uuid7(string $node = null): string
function uuid7(?DateTimeInterface $dateTime = null, string $node = null): string
{
return UUID::v7($node);
return UUID::v7($dateTime, $node);
}
}

Expand All @@ -109,12 +112,13 @@ function uuid8(string $node = null): string
/**
* Generates ULID.
*
* @param DateTimeInterface|null $dateTime
* @return string
* @throws Exception
*/
function ulid(): string
function ulid(?DateTimeInterface $dateTime = null): string
{
return ULID::generate();
return ULID::generate($dateTime);
}
}

Expand All @@ -125,7 +129,7 @@ function ulid(): string
* @param int $datacenter
* @param int $workerId
* @return string
* @throws SnowflakeException
* @throws SnowflakeException|FileLockException
*/
function snowflake(int $datacenter = 0, int $workerId = 0): string
{
Expand All @@ -139,7 +143,7 @@ function snowflake(int $datacenter = 0, int $workerId = 0): string
*
* @param int $machineId
* @return string
* @throws SonyflakeException
* @throws SonyflakeException|FileLockException
*/
function sonyflake(int $machineId = 0): string
{
Expand Down

0 comments on commit 32006cc

Please sign in to comment.