Skip to content

Commit

Permalink
[10.x] Switch to UUID v7 (#44210)
Browse files Browse the repository at this point in the history
* Switch to UUID v7

* Apply fixes from StyleCI

* Update HasUuids.php

Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
driesvints and StyleCIBot committed Sep 20, 2022
1 parent d50424f commit 8ec8c81
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 26 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -31,7 +31,7 @@
"psr/container": "^1.1.1|^2.0.1",
"psr/log": "^1.0|^2.0|^3.0",
"psr/simple-cache": "^1.0|^2.0|^3.0",
"ramsey/uuid": "^4.2.2",
"ramsey/uuid": "^4.5",
"symfony/console": "^6.2",
"symfony/error-handler": "^6.2",
"symfony/finder": "^6.2",
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Concerns/HasUuids.php
Expand Up @@ -29,7 +29,7 @@ public static function bootHasUuids()
*/
public function newUniqueId()
{
return (string) Str::orderedUuid();
return (string) Str::uuid();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/composer.json
Expand Up @@ -25,7 +25,7 @@
"illuminate/pipeline": "^10.0",
"illuminate/support": "^10.0",
"laravel/serializable-closure": "^1.0",
"ramsey/uuid": "^4.2.2",
"ramsey/uuid": "^4.5",
"symfony/process": "^6.2"
},
"autoload": {
Expand Down
26 changes: 4 additions & 22 deletions src/Illuminate/Support/Str.php
Expand Up @@ -10,10 +10,7 @@
use League\CommonMark\Extension\InlinesOnly\InlinesOnlyExtension;
use League\CommonMark\GithubFlavoredMarkdownConverter;
use League\CommonMark\MarkdownConverter;
use Ramsey\Uuid\Codec\TimestampFirstCombCodec;
use Ramsey\Uuid\Generator\CombGenerator;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidFactory;
use Symfony\Component\Uid\Ulid;
use Traversable;
use voku\helper\ASCII;
Expand Down Expand Up @@ -1220,40 +1217,25 @@ public static function wordCount($string, $characters = null)
}

/**
* Generate a UUID (version 4).
* Generate a UUID (version 7).
*
* @return \Ramsey\Uuid\UuidInterface
*/
public static function uuid()
{
return static::$uuidFactory
? call_user_func(static::$uuidFactory)
: Uuid::uuid4();
: Uuid::uuid7();
}

/**
* Generate a time-ordered UUID (version 4).
* Generate a time-ordered UUID (version 7).
*
* @return \Ramsey\Uuid\UuidInterface
*/
public static function orderedUuid()
{
if (static::$uuidFactory) {
return call_user_func(static::$uuidFactory);
}

$factory = new UuidFactory;

$factory->setRandomGenerator(new CombGenerator(
$factory->getRandomGenerator(),
$factory->getNumberConverter()
));

$factory->setCodec(new TimestampFirstCombCodec(
$factory->getUuidBuilder()
));

return $factory->uuid4();
return Str::uuid();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/composer.json
Expand Up @@ -44,7 +44,7 @@
"suggest": {
"illuminate/filesystem": "Required to use the composer class (^10.0).",
"league/commonmark": "Required to use Str::markdown() and Stringable::markdown() (^2.0.2).",
"ramsey/uuid": "Required to use Str::uuid() (^4.2.2).",
"ramsey/uuid": "Required to use Str::uuid() (^4.5).",
"symfony/process": "Required to use the composer class (^6.2).",
"symfony/uid": "Required to use Str::ulid() (^6.2).",
"symfony/var-dumper": "Required to use the dd function (^6.2).",
Expand Down

0 comments on commit 8ec8c81

Please sign in to comment.