Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getDefinedOptions example
$this
->parents =
[
]
;
$this
->extensions =
[
]
;
if
(
null !==
$type
->
getParent
(
)
)
{
$optionsResolver
=
clone
$this
->
getParentOptionsResolver
(
$type
->
getParent
(
)
)
;
}
else
{
$optionsResolver
=
new
OptionsResolver
(
)
;
}
$type
->
getInnerType
(
)
->
configureOptions
(
$ownOptionsResolver
=
new
OptionsResolverWrapper
(
)
)
;
$this
->ownOptions =
array_diff
(
$ownOptionsResolver
->
getDefinedOptions
(
)
,
$optionsResolver
->
getDefinedOptions
(
)
)
;
$overriddenOptions
=
array_intersect
(
array_merge
(
$ownOptionsResolver
->
getDefinedOptions
(
)
,
$ownOptionsResolver
->
getUndefinedOptions
(
)
)
,
$optionsResolver
->
getDefinedOptions
(
)
)
;
$this
->parentOptions =
[
]
;
foreach
(
$this
->parents
as
$class
=>
$parentOptions
)
{
$this
->overriddenOptions
[
$class
]
=
array_intersect
(
$overriddenOptions
,
$parentOptions
)
;
$this
->parentOptions
[
$class
]
=
array_diff
(
$parentOptions
,
$overriddenOptions
)
;
}
$type
->
getInnerType
(
)
->
configureOptions
(
$optionsResolver
)
;
$this
->
collectTypeExtensionsOptions
(
$type
,
$optionsResolver
)
;
$this
->extensionOptions =
[
]
;
$this
->
assertFalse
(
$this
->resolver->
isDefined
(
'foo'
)
)
;
$this
->resolver->
setDefault
(
'foo', 'bar'
)
;
$this
->
assertTrue
(
$this
->resolver->
isDefined
(
'foo'
)
)
;
}
public
function
testGetDefinedOptions
(
)
{
$this
->resolver->
setDefined
(
[
'foo', 'bar'
]
)
;
$this
->resolver->
setDefault
(
'baz', 'bam'
)
;
$this
->resolver->
setRequired
(
'boo'
)
;
$this
->
assertSame
(
[
'foo', 'bar', 'baz', 'boo'
]
,
$this
->resolver->
getDefinedOptions
(
)
)
;
}
public
function
testRemovedOptionsAreNotDefined
(
)
{
$this
->
assertFalse
(
$this
->resolver->
isDefined
(
'foo'
)
)
;
$this
->resolver->
setDefined
(
'foo'
)
;
$this
->
assertTrue
(
$this
->resolver->
isDefined
(
'foo'
)
)
;
$this
->resolver->
remove
(
'foo'
)
;
$this
->
assertFalse
(
$this
->resolver->
isDefined
(
'foo'
)
)
;
}
if
(
!
class_exists
(
$class
)
|| !
is_subclass_of
(
$class
, FormTypeInterface::
class
)
)
{
$class
=
$this
->
getFqcnTypeClass
(
$input
,
$io
,
$class
)
;
}
$resolvedType
=
$this
->formRegistry->
getType
(
$class
)
;
if
(
$option
=
$input
->
getArgument
(
'option'
)
)
{
$object
=
$resolvedType
->
getOptionsResolver
(
)
;
if
(
!
$object
->
isDefined
(
$option
)
)
{
$message
=
sprintf
(
'Option "%s" is not defined in "%s".',
$option
,
$resolvedType
->
getInnerType
(
)
::
class
)
;
if
(
$alternatives
=
$this
->
findAlternatives
(
$option
,
$object
->
getDefinedOptions
(
)
)
)
{
if
(
1 === \
count
(
$alternatives
)
)
{
$message
.= "\n\nDid you mean this?\n ";
}
else
{
$message
.= "\n\nDid you mean one of these?\n ";
}
$message
.=
implode
(
"\n ",
$alternatives
)
;
}
throw
new
InvalidArgumentException
(
$message
)
;
}