kbsali / php-redmine-api

A simple PHP Redmine API client, Object Oriented

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Third party package support: Could not create XML from array

dzandrey opened this issue · comments

Could you add support for redmine tags - https://www.redmine.org/plugins/redmineup_tags

In my example, I am passing an array

Redmine::issue()->create(
    // ...
    'tag_list' => [
      'approved',
      'finished',
    ],
);

But I get an error

Redmine \ Exception \ SerializerException
Could not create XML from array: ""

I added a fix to this PR - #379, but it was rejected.

I cannot find any REST API documentation for this tags plugin, but if I understand your issue and #379 correctly you would like to have general array support in XmlSerializer class to make something like this possible:

$serializer = XmlSerializer::createFromArray([
    'issue' => [
        'tag_list' => [
            'approved',
            'finished',
        ],
    ],
]);

var_dump($serializer->__toString());

The generated XML should then look like this:

<?xml version="1.0"?>
<issue>
    <tag_list type="array">
        <tag_list>approved</tag_list>
        <tag_list>finished</tag_list>
    </tag_list>
</issue>

Is this correct?

Yes.

SimpleXMLElement Object
(
    [tag_list] => SimpleXMLElement Object
    (
        [@attributes] => Array
            (
                [type] => array
            )

        [tag_list] => Array
            (
                [0] => approved
                [1] => finished
            )
    )
)

@dzandrey I've create #394 to implement this.