minor #36153 [Uid] minor improvements (nicolas-grekas)
This PR was merged into the 5.1-dev branch.
Discussion
----------
[Uid] minor improvements
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| Deprecations? | no
| Tickets | -
| License | MIT
| Doc PR | -
Commits
-------
660326bed3
[Uid] minor improvements
This commit is contained in:
commit
80672fb12a
|
@ -78,6 +78,7 @@
|
|||
<element key="5"><string>Symfony\Component\Cache\Traits</string></element>
|
||||
<element key="6"><string>Symfony\Component\Console</string></element>
|
||||
<element key="7"><string>Symfony\Component\HttpFoundation</string></element>
|
||||
<element key="8"><string>Symfony\Component\Uid</string></element>
|
||||
</array>
|
||||
</element>
|
||||
</array>
|
||||
|
|
|
@ -74,7 +74,13 @@ abstract class AbstractUid implements \JsonSerializable
|
|||
*/
|
||||
public function toRfc4122(): string
|
||||
{
|
||||
return uuid_unparse($this->toBinary());
|
||||
// don't use uuid_unparse(), it's slower
|
||||
$uuid = bin2hex($this->toBinary());
|
||||
$uuid = substr_replace($uuid, '-', 8, 0);
|
||||
$uuid = substr_replace($uuid, '-', 13, 0);
|
||||
$uuid = substr_replace($uuid, '-', 18, 0);
|
||||
|
||||
return substr_replace($uuid, '-', 23, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace Symfony\Component\Uid;
|
|||
*/
|
||||
class Ulid extends AbstractUid
|
||||
{
|
||||
private static $time = -1;
|
||||
private static $time = '';
|
||||
private static $rand = [];
|
||||
|
||||
public function __construct(string $ulid = null)
|
||||
|
|
|
@ -41,7 +41,12 @@ class Uuid extends AbstractUid
|
|||
}
|
||||
|
||||
if (16 === \strlen($uuid)) {
|
||||
$uuid = uuid_unparse($uuid);
|
||||
// don't use uuid_unparse(), it's slower
|
||||
$uuid = bin2hex($uuid);
|
||||
$uuid = substr_replace($uuid, '-', 8, 0);
|
||||
$uuid = substr_replace($uuid, '-', 13, 0);
|
||||
$uuid = substr_replace($uuid, '-', 18, 0);
|
||||
$uuid = substr_replace($uuid, '-', 23, 0);
|
||||
} elseif (26 === \strlen($uuid) && Ulid::isValid($uuid)) {
|
||||
$uuid = (new Ulid($uuid))->toRfc4122();
|
||||
}
|
||||
|
|
|
@ -27,4 +27,14 @@
|
|||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
|
||||
<listeners>
|
||||
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
|
||||
<arguments>
|
||||
<array>
|
||||
<element key="time-sensitive"><string>Symfony\Component\Uid</string></element>
|
||||
</array>
|
||||
</arguments>
|
||||
</listener>
|
||||
</listeners>
|
||||
</phpunit>
|
||||
|
|
Reference in New Issue