[Uid] minor improvements
This commit is contained in:
parent
7e181b93ca
commit
660326bed3
|
@ -78,6 +78,7 @@
|
||||||
<element key="5"><string>Symfony\Component\Cache\Traits</string></element>
|
<element key="5"><string>Symfony\Component\Cache\Traits</string></element>
|
||||||
<element key="6"><string>Symfony\Component\Console</string></element>
|
<element key="6"><string>Symfony\Component\Console</string></element>
|
||||||
<element key="7"><string>Symfony\Component\HttpFoundation</string></element>
|
<element key="7"><string>Symfony\Component\HttpFoundation</string></element>
|
||||||
|
<element key="8"><string>Symfony\Component\Uid</string></element>
|
||||||
</array>
|
</array>
|
||||||
</element>
|
</element>
|
||||||
</array>
|
</array>
|
||||||
|
|
|
@ -74,7 +74,13 @@ abstract class AbstractUid implements \JsonSerializable
|
||||||
*/
|
*/
|
||||||
public function toRfc4122(): string
|
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
|
class Ulid extends AbstractUid
|
||||||
{
|
{
|
||||||
private static $time = -1;
|
private static $time = '';
|
||||||
private static $rand = [];
|
private static $rand = [];
|
||||||
|
|
||||||
public function __construct(string $ulid = null)
|
public function __construct(string $ulid = null)
|
||||||
|
|
|
@ -41,7 +41,12 @@ class Uuid extends AbstractUid
|
||||||
}
|
}
|
||||||
|
|
||||||
if (16 === \strlen($uuid)) {
|
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)) {
|
} elseif (26 === \strlen($uuid) && Ulid::isValid($uuid)) {
|
||||||
$uuid = (new Ulid($uuid))->toRfc4122();
|
$uuid = (new Ulid($uuid))->toRfc4122();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,4 +27,14 @@
|
||||||
</exclude>
|
</exclude>
|
||||||
</whitelist>
|
</whitelist>
|
||||||
</filter>
|
</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>
|
</phpunit>
|
||||||
|
|
Reference in New Issue