Currently the ParamsTrait trait ignores the array structure of the params JSON node and treats the first object within it as an associative array representing the params.
Example:
{
"params": [
{
"param1": "test",
"param2": "also test"
}
]
}
This results in an associative array returned by getParams() like the one below:
array (
'param1' => 'test',
'param2' => 'also test'
);
Adding another param in a syntax one would expect does not result in any more params to be returned by getParams method, as internally PHPs reset() function is used which leads to ignoring all other objects in the JSON array.
Example of JSON native second param (second param gets ignored by ParamsTrait):
{
"params" : [
{
"param1": "test",
"param2": "also test"
},
{
"param1": "test",
"param2": "also test"
}
]
}
I understand this design decision was made so the getParam() method can be used to retrieve actual params (like param1) by key, but from a JSON point of view the configuration syntax is misleading and not easily understood.
I would propose to change the JSON structure within params nodes to be objects so they can be used with getParams() (as associative array) and getParam() by the actual keys within the object.
Example based on the param extension above would be:
{
"params" : {
"param1":
{
"param1": "test",
"param2": "also test"
},
"param2": {
"param1": "test",
"param2": "also test"
}
}
}
This follows the native JSON structure and is easily extendable.
Currently the
ParamsTraittrait ignores the array structure of theparamsJSON node and treats the first object within it as an associative array representing the params.Example:
{ "params": [ { "param1": "test", "param2": "also test" } ] }This results in an associative array returned by
getParams()like the one below:Adding another param in a syntax one would expect does not result in any more params to be returned by
getParamsmethod, as internally PHPsreset()function is used which leads to ignoring all other objects in the JSON array.Example of JSON native second param (second param gets ignored by
ParamsTrait):{ "params" : [ { "param1": "test", "param2": "also test" }, { "param1": "test", "param2": "also test" } ] }I understand this design decision was made so the
getParam()method can be used to retrieve actual params (likeparam1) by key, but from a JSON point of view the configuration syntax is misleading and not easily understood.I would propose to change the JSON structure within
paramsnodes to be objects so they can be used withgetParams()(as associative array) andgetParam()by the actual keys within the object.Example based on the param extension above would be:
{ "params" : { "param1": { "param1": "test", "param2": "also test" }, "param2": { "param1": "test", "param2": "also test" } } }This follows the native JSON structure and is easily extendable.