Skip to content

Commit 8ec8c81

Browse files
[10.x] Switch to UUID v7 (#44210)
* Switch to UUID v7 * Apply fixes from StyleCI * Update HasUuids.php Co-authored-by: StyleCI Bot <[email protected]>
1 parent d50424f commit 8ec8c81

File tree

5 files changed

+8
-26
lines changed

5 files changed

+8
-26
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"psr/container": "^1.1.1|^2.0.1",
3232
"psr/log": "^1.0|^2.0|^3.0",
3333
"psr/simple-cache": "^1.0|^2.0|^3.0",
34-
"ramsey/uuid": "^4.2.2",
34+
"ramsey/uuid": "^4.5",
3535
"symfony/console": "^6.2",
3636
"symfony/error-handler": "^6.2",
3737
"symfony/finder": "^6.2",

src/Illuminate/Database/Eloquent/Concerns/HasUuids.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function bootHasUuids()
2929
*/
3030
public function newUniqueId()
3131
{
32-
return (string) Str::orderedUuid();
32+
return (string) Str::uuid();
3333
}
3434

3535
/**

src/Illuminate/Queue/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"illuminate/pipeline": "^10.0",
2626
"illuminate/support": "^10.0",
2727
"laravel/serializable-closure": "^1.0",
28-
"ramsey/uuid": "^4.2.2",
28+
"ramsey/uuid": "^4.5",
2929
"symfony/process": "^6.2"
3030
},
3131
"autoload": {

src/Illuminate/Support/Str.php

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
use League\CommonMark\Extension\InlinesOnly\InlinesOnlyExtension;
1111
use League\CommonMark\GithubFlavoredMarkdownConverter;
1212
use League\CommonMark\MarkdownConverter;
13-
use Ramsey\Uuid\Codec\TimestampFirstCombCodec;
14-
use Ramsey\Uuid\Generator\CombGenerator;
1513
use Ramsey\Uuid\Uuid;
16-
use Ramsey\Uuid\UuidFactory;
1714
use Symfony\Component\Uid\Ulid;
1815
use Traversable;
1916
use voku\helper\ASCII;
@@ -1220,40 +1217,25 @@ public static function wordCount($string, $characters = null)
12201217
}
12211218

12221219
/**
1223-
* Generate a UUID (version 4).
1220+
* Generate a UUID (version 7).
12241221
*
12251222
* @return \Ramsey\Uuid\UuidInterface
12261223
*/
12271224
public static function uuid()
12281225
{
12291226
return static::$uuidFactory
12301227
? call_user_func(static::$uuidFactory)
1231-
: Uuid::uuid4();
1228+
: Uuid::uuid7();
12321229
}
12331230

12341231
/**
1235-
* Generate a time-ordered UUID (version 4).
1232+
* Generate a time-ordered UUID (version 7).
12361233
*
12371234
* @return \Ramsey\Uuid\UuidInterface
12381235
*/
12391236
public static function orderedUuid()
12401237
{
1241-
if (static::$uuidFactory) {
1242-
return call_user_func(static::$uuidFactory);
1243-
}
1244-
1245-
$factory = new UuidFactory;
1246-
1247-
$factory->setRandomGenerator(new CombGenerator(
1248-
$factory->getRandomGenerator(),
1249-
$factory->getNumberConverter()
1250-
));
1251-
1252-
$factory->setCodec(new TimestampFirstCombCodec(
1253-
$factory->getUuidBuilder()
1254-
));
1255-
1256-
return $factory->uuid4();
1238+
return Str::uuid();
12571239
}
12581240

12591241
/**

src/Illuminate/Support/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"suggest": {
4545
"illuminate/filesystem": "Required to use the composer class (^10.0).",
4646
"league/commonmark": "Required to use Str::markdown() and Stringable::markdown() (^2.0.2).",
47-
"ramsey/uuid": "Required to use Str::uuid() (^4.2.2).",
47+
"ramsey/uuid": "Required to use Str::uuid() (^4.5).",
4848
"symfony/process": "Required to use the composer class (^6.2).",
4949
"symfony/uid": "Required to use Str::ulid() (^6.2).",
5050
"symfony/var-dumper": "Required to use the dd function (^6.2).",

0 commit comments

Comments
 (0)