sorry for the title I know is not as explanatory as I would like.
I am creating a configuration file for a bundle, and I want that en element to be defined in several ways.
These are the different ways I want to be able to define my entry:
properties:
property1: ~
property2: ~
property3: Custom label3
property4:
label: Custom label4
type: int
Or
properties:
- property1
- property2
- { property: property3, label: Custom label3 }
- { property: property4, label: Custom label4, type: int }
Both configurations should result in the following structure:
"properties" => [
"property1" => [
"label": null
"type": null
],
"property2" => [
"label": null
"type": null
],
"property3" => [
"label": "Custom label 3"
"type": null
],
"property4" => [
"label": "Custom label 4"
"type": "int"
],
]
This is the current code I have:
->arrayNode('properties')
->useAttributeAsKey('property')
->arrayPrototype()
->beforeNormalization()
->ifString()->then(function($item) { return ['property' => $item]; })
->end()
->children()
->scalarNode('property')->defaultNull()->end()
->scalarNode('label')->defaultNull()->end()
->scalarNode('type')->defaultNull()->end()
->end()
->end()
->end()
Wit the first code I am receiving the following result, which is almost perfect:
"properties" => array:4 [
"property1" => array:3 [
"property" => null
"label" => null
"type" => null
]
"property2" => array:3 [
"property" => null
"label" => null
"type" => null
]
"property3" => array:3 [
"property" => "Custom label3"
"label" => null
"type" => null
]
"property4" => array:3 [
"label" => "Custom label4"
"type" => "int"
"property" => null
]
]
In each entry it has the "property" => null
. How can I remove the property as it is already in the key?
With the second example I am receiving the following result:
"properties" => array:4 [
0 => array:3 [
"property" => "property1"
"label" => null
"type" => null
]
1 => array:3 [
"property" => "property2"
"label" => null
"type" => null
]
"property3" => array:3 [
"label" => "Custom label 3"
"property" => null
"type" => null
]
"property4" => array:3 [
"label" => "Custom label 4"
"type" => "int"
"property" => null
]
]
As you can see, first two entries doesn't have the property
as key, it has a number like a normal array. How can I solve it?
Thank you