Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
floatNode example
->
scalarNode
(
'lastMod'
)
->
end
(
)
->
enumNode
(
'changeFreq'
)
->
values
(
[
'always',
'hourly',
'daily',
'weekly',
'monthly',
'yearly',
]
)
->
end
(
)
->
floatNode
(
'priority'
)
->
end
(
)
->
scalarNode
(
'salesChannelId'
)
->
end
(
)
->
end
(
)
->
end
(
)
->
end
(
)
->
arrayNode
(
'excluded_urls'
)
->
arrayPrototype
(
)
->
children
(
)
->
scalarNode
(
'resource'
)
->
end
(
)
->
scalarNode
(
'identifier'
)
->
end
(
)
->
scalarNode
(
'salesChannelId'
)
->
end
(
)
->
end
(
)
class
PrimitiveTypes
implements
ConfigurationInterface
{
public
function
getConfigTreeBuilder
(
)
: TreeBuilder
{
$tb
=
new
TreeBuilder
(
'primitive_types'
)
;
$rootNode
=
$tb
->
getRootNode
(
)
;
$rootNode
->
children
(
)
->
booleanNode
(
'boolean_node'
)
->
end
(
)
->
enumNode
(
'enum_node'
)
->
values
(
[
'foo', 'bar', 'baz', TestEnum::Bar
]
)
->
end
(
)
->
floatNode
(
'float_node'
)
->
end
(
)
->
integerNode
(
'integer_node'
)
->
end
(
)
->
scalarNode
(
'scalar_node'
)
->
end
(
)
->
scalarNode
(
'scalar_node_with_default'
)
->
defaultTrue
(
)
->
end
(
)
->
end
(
)
;
return
$tb
;
}
}
$this
->
assertInstanceOf
(
$node1
::
class
,
$node2
)
;
}
public
function
testNumericNodeCreation
(
)
{
$builder
=
new
BaseNodeBuilder
(
)
;
$node
=
$builder
->
integerNode
(
'foo'
)
->
min
(
3
)
->
max
(
5
)
;
$this
->
assertInstanceOf
(
IntegerNodeDefinition::
class
,
$node
)
;
$node
=
$builder
->
floatNode
(
'bar'
)
->
min
(
3.0
)
->
max
(
5.0
)
;
$this
->
assertInstanceOf
(
FloatNodeDefinition::
class
,
$node
)
;
}
}
class
SomeNodeDefinition
extends
BaseVariableNodeDefinition
{
}
use
Symfony\Config\PrimitiveTypesConfig;
return
static
function
DPrimitiveTypesConfig
$config
)
{
$config
->
booleanNode
(
true
)
;
$config
->
enumNode
(
'foo'
)
;
$config
->
floatNode
(
47.11
)
;
$config
->
integerNode
(
1337
)
;
$config
->
scalarNode
(
'foobar'
)
;
$config
->
scalarNodeWithDefault
(
null
)
;
}
;
->
info
(
'The default path used to load translations'
)
->
defaultValue
(
'%kernel.project_dir%/translations'
)
->
end
(
)
->
arrayNode
(
'paths'
)
->
prototype
(
'scalar'
)
->
end
(
)
->
end
(
)
->
arrayNode
(
'pseudo_localization'
)
->
canBeEnabled
(
)
->
fixXmlConfig
(
'localizable_html_attribute'
)
->
children
(
)
->
booleanNode
(
'accents'
)
->
defaultTrue
(
)
->
end
(
)
->
floatNode
(
'expansion_factor'
)
->
min
(
1.0
)
->
defaultValue
(
1.0
)
->
end
(
)
->
booleanNode
(
'brackets'
)
->
defaultTrue
(
)
->
end
(
)
->
booleanNode
(
'parse_html'
)
->
defaultFalse
(
)
->
end
(
)
->
arrayNode
(
'localizable_html_attributes'
)
->
prototype
(
'scalar'
)
->
end
(
)
->
end
(
)
->
end
(
)
->
end
(
)
->
arrayNode
(
'providers'
)
use
Symfony\Component\Config\Definition\ConfigurationInterface;
class
Placeholders
implements
ConfigurationInterface
{
public
function
getConfigTreeBuilder
(
)
: TreeBuilder
{
$tb
=
new
TreeBuilder
(
'placeholders'
)
;
$rootNode
=
$tb
->
getRootNode
(
)
;
$rootNode
->
children
(
)
->
booleanNode
(
'enabled'
)
->
defaultFalse
(
)
->
end
(
)
->
floatNode
(
'favorite_float'
)
->
end
(
)
->
arrayNode
(
'good_integers'
)
->
integerPrototype
(
)
->
end
(
)
->
end
(
)
->
end
(
)
;
return
$tb
;
}
}
$treeBuilder
->
getRootNode
(
)
->
children
(
)
->
scalarNode
(
'scalar_node'
)
->
end
(
)
->
scalarNode
(
'scalar_node_not_empty'
)
->
cannotBeEmpty
(
)
->
end
(
)
->
scalarNode
(
'scalar_node_not_empty_validated'
)
->
cannotBeEmpty
(
)
->
validate
(
)
->
always
(
fn
(
$value
)
=>
$value
)
->
end
(
)
->
end
(
)
->
integerNode
(
'int_node'
)
->
end
(
)
->
floatNode
(
'float_node'
)
->
end
(
)
->
booleanNode
(
'bool_node'
)
->
end
(
)
->
arrayNode
(
'array_node'
)
->
beforeNormalization
(
)
->
ifTrue
(
fn
(
$value
)
=> !\
is_array
(
$value
)
)
->
then
(
fn
(
$value
)
=>
[
'child_node' =>
$value
]
)
->
end
(
)
->
beforeNormalization
(
)
->
ifArray
(
)
->
then
(
function
Darray
$v
)
{
if
(
isset
(
$v
[
'bool_force_cast'
]
)
)
{
$v
[
'bool_force_cast'
]
=
(bool)
$v
[
'bool_force_cast'
]
;
}