Skip to content

Configuration\Jms\Configuration\ParamsTrait ignores JSON array structure #112

@wick-ed

Description

@wick-ed

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions