首页 > 解决方案 > 转储函数在使用 TaggedValue 时忽略内联参数

问题描述

我的Yaml::Dump()功能有问题。当我使用 TaggedValue 时,转储函数会忽略参数 $inline

如果我没有使用 TaggedValues,它会按预期工作。

这是使用的示例代码

 use Symfony\Component\Yaml\Yaml;
 use Symfony\Component\Yaml\Tag\TaggedValue;

$Admins = array(
        array(
            'samaccountname' => ['user1'],
            'cn' => ['Louisa Nicolas'],
            'mail' => ['mail@domain.com'],
        ),
        array(
            'samaccountname' => ['user2'],
            'cn' => ['Telper Max'],
            'mail' => ['mail@domain.com'],
        )
    );

    $rootYaml = array();
    foreach ($Admins as $Admin) {
        $adm = array(
            'id' => $Admin['samaccountname'][0],
            'annotations' => array(
                'name' => $Admin['cn'][0],
                'email' => $Admin['mail'][0]
        ));
        $rootYaml[] = $adm;
        $rootYamlTagged[] = new TaggedValue('user', $adm);
    }
    echo "##### Works without tags\n";
    print Yaml::dump($rootYaml, 3);
    echo "##### not working with tags\n";
    print Yaml::dump($rootYamlTagged, 3);

结果 :

##### Works without tags
-
    id: user1
    annotations:
        name: 'Louisa Nicolas'
        email: mail@domain.com
-
    id: user2
    annotations:
        name: 'Telper Max'
        email: mail@domain.com
##### not working with tags
- !user { id: user1, annotations: { name: 'Louisa Nicolas', email: mail@domain.com } }
- !user { id: user2, annotations: { name: 'Telper Max', email: mail@domain.com } }

我希望有标记

- !user 
  id: user1, 
  annotations: 
    name: 'Louisa Nicolas'
    email: mail@domain.com
- !user
  id: user2
  annotations: 
    name: 'Telper Max'
    email: mail@domain.com 

我在支持团队中为此打开了一个错误,并确认了错误。

Yaml 转储:使用 TaggedValue 时忽略内联参数

标签: phpsymfonyyamlsymfony4

解决方案


Bug has been approved. It's fixed in version 3.4.

The pull request [Yaml] fix inline handling when dumping tagged values has the actual code changes.


推荐阅读