-
-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #994 from bavix/identifier
[11.3] UUID7. IdentifierFactoryServiceInterface
- Loading branch information
Showing
17 changed files
with
136 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
use Bavix\Wallet\Internal\Service\ConnectionService; | ||
Check notice on line 22 in config/config.php GitHub Actions / Qodana for PHPUsage of internal entity
|
||
use Bavix\Wallet\Internal\Service\DatabaseService; | ||
use Bavix\Wallet\Internal\Service\DispatcherService; | ||
use Bavix\Wallet\Internal\Service\IdentifierFactoryService; | ||
use Bavix\Wallet\Internal\Service\JsonService; | ||
Check notice on line 26 in config/config.php GitHub Actions / Qodana for PHPUsage of internal entity
|
||
use Bavix\Wallet\Internal\Service\LockService; | ||
use Bavix\Wallet\Internal\Service\MathService; | ||
|
@@ -209,8 +210,18 @@ | |
* The service for generating UUIDs. | ||
* | ||
* @var string | ||
* | ||
* @deprecated use identifier. | ||
* @see IdentifierFactoryService | ||
*/ | ||
'uuid' => UuidFactoryService::class, | ||
|
||
/** | ||
* The service for generating identifiers. | ||
* | ||
* @var string | ||
*/ | ||
'identifier' => IdentifierFactoryService::class, | ||
], | ||
|
||
/** | ||
|
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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bavix\Wallet\Internal\Service; | ||
|
||
use Ramsey\Uuid\Exception\InvalidArgumentException; | ||
use Ramsey\Uuid\Exception\InvalidUuidStringException; | ||
use Ramsey\Uuid\Exception\UnsupportedOperationException; | ||
use Ramsey\Uuid\Exception\UuidExceptionInterface; | ||
use Ramsey\Uuid\UuidFactory; | ||
|
||
final readonly class IdentifierFactoryService implements IdentifierFactoryServiceInterface | ||
{ | ||
/** | ||
* @param UuidFactory $uuidFactory Service for generating UUIDs. | ||
* @param ClockServiceInterface $clockService Service for getting the current time. | ||
*/ | ||
public function __construct( | ||
private UuidFactory $uuidFactory, | ||
private ClockServiceInterface $clockService, | ||
) { | ||
} | ||
|
||
/** | ||
* Generate a ID string using the uuid7 algorithm. | ||
* | ||
* uuid7 is a time-based UUID algorithm that uses the current time in milliseconds, | ||
* combined with a random number to generate a unique ID. | ||
* | ||
* @return non-empty-string The generated ID string. | ||
* | ||
* @throws InvalidArgumentException If a field is invalid in the UUID. | ||
* @throws InvalidUuidStringException If the string we are parsing is not a valid UUID. | ||
* @throws UnsupportedOperationException If the UUID implementation can't support a feature. | ||
* @throws UuidExceptionInterface If there is an error generating the UUID. | ||
*/ | ||
public function generate(): string | ||
{ | ||
return $this->uuidFactory->uuid7($this->clockService->now()) | ||
->toString(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Internal/Service/IdentifierFactoryServiceInterface.php
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bavix\Wallet\Internal\Service; | ||
|
||
use Ramsey\Uuid\Exception\InvalidArgumentException; | ||
use Ramsey\Uuid\Exception\InvalidUuidStringException; | ||
use Ramsey\Uuid\Exception\UnsupportedOperationException; | ||
use Ramsey\Uuid\Exception\UuidExceptionInterface; | ||
|
||
interface IdentifierFactoryServiceInterface | ||
{ | ||
/** | ||
* Generate a unique identifier string. | ||
* | ||
* This method generates a unique identifier string using internal algorithm. | ||
* | ||
* @return non-empty-string The generated ID string. | ||
* | ||
* @throws InvalidArgumentException If a field is invalid in the UUID. | ||
* @throws InvalidUuidStringException If the string we are parsing is not a valid UUID. | ||
* @throws UnsupportedOperationException If the UUID implementation can't support a feature. | ||
* @throws UuidExceptionInterface If there is an error generating the UUID. | ||
*/ | ||
public function generate(): string; | ||
} |
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
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
Oops, something went wrong.