Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getDefaultOption example
$options
[
'payload'
]
=
$payload
??
$options
[
'payload'
]
?? null;
foreach
(
$options
as
$name
=>
$value
)
{
$this
->
$name
=
$value
;
}
}
protected
function
normalizeOptions
(
mixed
$options
)
: array
{
$normalizedOptions
=
[
]
;
$defaultOption
=
$this
->
getDefaultOption
(
)
;
$invalidOptions
=
[
]
;
$missingOptions
=
array_flip
(
(array)
$this
->
getRequiredOptions
(
)
)
;
$knownOptions
=
get_class_vars
(
static
::
class
)
;
if
(
\
is_array
(
$options
)
&&
isset
(
$options
[
'value'
]
)
&& !
property_exists
(
$this
, 'value'
)
)
{
if
(
null ===
$defaultOption
)
{
throw
new
ConstraintDefinitionException
(
sprintf
(
'No default option is configured for constraint "%s".',
static
::
class
)
)
;
}
$options
[
$defaultOption
]
=
$options
[
'value'
]
;
unset
(
$options
[
'value'
]
)
;
}
/** * {@inheritdoc} */
public
function
getDefaultOption
(
)
{
return
'field_name';
}
/** * {@inheritdoc} */
public
function
getRequiredOptions
(
)
{
return
(array)
$this
->
getDefaultOption
(
)
;
}
}
$options
[
'payload'
]
=
$payload
??
$options
[
'payload'
]
?? null;
foreach
(
$options
as
$name
=>
$value
)
{
$this
->
$name
=
$value
;
}
}
protected
function
normalizeOptions
(
mixed
$options
)
: array
{
$normalizedOptions
=
[
]
;
$defaultOption
=
$this
->
getDefaultOption
(
)
;
$invalidOptions
=
[
]
;
$missingOptions
=
array_flip
(
(array)
$this
->
getRequiredOptions
(
)
)
;
$knownOptions
=
get_class_vars
(
static
::
class
)
;
if
(
\
is_array
(
$options
)
&&
isset
(
$options
[
'value'
]
)
&& !
property_exists
(
$this
, 'value'
)
)
{
if
(
null ===
$defaultOption
)
{
throw
new
ConstraintDefinitionException
(
sprintf
(
'No default option is configured for constraint "%s".',
static
::
class
)
)
;
}
$options
[
$defaultOption
]
=
$options
[
'value'
]
;
unset
(
$options
[
'value'
]
)
;
}