Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
v3 example
public
function
__construct
(
string
$class
, Uuid
$namespace
)
{
$this
->class =
$class
;
$this
->namespace =
$namespace
;
}
public
function
create
(
string
$name
)
: UuidV5|UuidV3
{
switch
(
$class
=
$this
->class
)
{
case
UuidV5::
class
:
return
Uuid::
v5
(
$this
->namespace,
$name
)
;
case
UuidV3::
class
:
return
Uuid::
v3
(
$this
->namespace,
$name
)
;
}
if
(
is_subclass_of
(
$class
, UuidV5::
class
)
)
{
$uuid
= Uuid::
v5
(
$this
->namespace,
$name
)
;
}
else
{
$uuid
= Uuid::
v3
(
$this
->namespace,
$name
)
;
}
return
new
$class
(
$uuid
)
;
}
}
$this
->
assertInstanceOf
(
UuidV1::
class
,
$uuid
)
;
$uuid
=
new
UuidV1
(
self::A_UUID_V1
)
;
$this
->
assertEquals
(
\DateTimeImmutable::
createFromFormat
(
'U.u', '1583245966.746458'
)
,
$uuid
->
getDateTime
(
)
)
;
$this
->
assertSame
(
'3499710062d0',
$uuid
->
getNode
(
)
)
;
}
public
function
testV3
(
)
{
$uuid
= Uuid::
v3
(
new
UuidV4
(
self::A_UUID_V4
)
, 'the name'
)
;
$this
->
assertInstanceOf
(
UuidV3::
class
,
$uuid
)
;
$this
->
assertSame
(
'8dac64d3-937a-3e7c-aa1d-d5d6c06a61f5',
(string)
$uuid
)
;
}
public
function
testV4
(
)
{
$uuid
= Uuid::
v4
(
)
;
$this
->
assertInstanceOf
(
UuidV4::
class
,
$uuid
)
;
}
private
UidNormalizer
$normalizer
;
protected
function
setUp
(
)
: void
{
$this
->normalizer =
new
UidNormalizer
(
)
;
}
public
function
testSupportsNormalization
(
)
{
$this
->
assertTrue
(
$this
->normalizer->
supportsNormalization
(
Uuid::
v1
(
)
)
)
;
$this
->
assertTrue
(
$this
->normalizer->
supportsNormalization
(
Uuid::
v3
(
Uuid::
v1
(
)
, 'foo'
)
)
)
;
$this
->
assertTrue
(
$this
->normalizer->
supportsNormalization
(
Uuid::
v4
(
)
)
)
;
$this
->
assertTrue
(
$this
->normalizer->
supportsNormalization
(
Uuid::
v5
(
Uuid::
v1
(
)
, 'foo'
)
)
)
;
$this
->
assertTrue
(
$this
->normalizer->
supportsNormalization
(
Uuid::
v6
(
)
)
)
;
$this
->
assertTrue
(
$this
->normalizer->
supportsNormalization
(
new
Ulid
(
)
)
)
;
$this
->
assertFalse
(
$this
->normalizer->
supportsNormalization
(
new
\
stdClass
(
)
)
)
;
}
public
static
function
normalizeProvider
(
)
{
$uidFormats
=
[
null, 'canonical', 'base58', 'base32', 'rfc4122'
]
;
$data
=
[
[