-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow using symfony/uid to generate ids
- Loading branch information
Showing
6 changed files
with
55 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kcs\MessengerExtra\Transport\Dbal; | ||
|
||
use Ramsey\Uuid\Uuid; | ||
use Ramsey\Uuid\UuidInterface; | ||
use RuntimeException; | ||
use Symfony\Component\Uid\Uuid as SymfonyUuid; | ||
|
||
use function class_exists; | ||
use function substr; | ||
|
||
final class MessageId | ||
{ | ||
public static function generate(): string | ||
{ | ||
if (class_exists(SymfonyUuid::class)) { | ||
$uuid = SymfonyUuid::v1(); | ||
|
||
return $uuid->toBinary(); | ||
} | ||
|
||
if (class_exists(UuidInterface::class)) { | ||
$uuid = Uuid::uuid1(); | ||
$bytes = $uuid->getFields()->getBytes(); | ||
|
||
return $bytes[6] . $bytes[7] | ||
. $bytes[4] . $bytes[5] | ||
. $bytes[0] . $bytes[1] . $bytes[2] . $bytes[3] | ||
. substr($bytes, 8); | ||
} | ||
|
||
throw new RuntimeException('No Uuid class found. Please install ramsey/uuid package or symfony/uid package.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters