Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
UuidConstraint example
$this
->
validate
(
$this
->
getConstraints
(
$field
)
,
$data
,
$parameters
->
getPath
(
)
)
;
}
}
}
if
(
$value
=== null
)
{
yield
$field
->
getStorageName
(
)
=> null;
return
;
}
if
(
$this
->
requiresValidation
(
$field
,
$existence
,
$value
,
$parameters
)
)
{
$this
->
validate
(
[
new
UuidConstraint
(
)
]
,
$data
,
$parameters
->
getPath
(
)
)
;
}
if
(
$value
!== null
)
{
$value
= Uuid::
fromHexToBytes
(
$value
)
;
}
yield
$field
->
getStorageName
(
)
=>
$value
;
}
public
function
decode
(
Field
$field
, mixed
$value
)
: ?string
{
Field
$field
,
EntityExistence
$existence
,
KeyValuePair
$data
,
WriteParameterBag
$parameters
)
: \Generator
{
if
(
!
$field
instanceof IdField
)
{
throw
DataAbstractionLayerException::
invalidSerializerField
(
IdField::
class
,
$field
)
;
}
$value
=
$data
->
getValue
(
)
;
if
(
$value
)
{
$this
->
validate
(
[
new
UuidConstraint
(
)
]
,
$data
,
$parameters
->
getPath
(
)
)
;
}
else
{
$value
= Uuid::
randomHex
(
)
;
}
$parameters
->
getContext
(
)
->
set
(
$parameters
->
getDefinition
(
)
->
getEntityName
(
)
,
$data
->
getKey
(
)
,
$value
)
;
yield
$field
->
getStorageName
(
)
=> Uuid::
fromHexToBytes
(
$value
)
;
}
public
function
decode
(
Field
$field
, mixed
$value
)
: ?string
{