php - 使用 TaggedValue 时转储函数忽略内联参数

标签 php symfony yaml symfony4

我对 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' => ['<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="224f434b4e62464d4f434b4c0c414d4f" rel="noreferrer noopener nofollow">[email protected]</a>'],
        ),
        array(
            'samaccountname' => ['user2'],
            'cn' => ['Telper Max'],
            'mail' => ['<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="066b676f6a4662696b676f682865696b" rel="noreferrer noopener nofollow">[email protected]</a>'],
        )
    );

    $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: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5439353d3814303b39353d3a7a373b39" rel="noreferrer noopener nofollow">[email protected]</a>
-
    id: user2
    annotations:
        name: 'Telper Max'
        email: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="eb868a8287ab8f84868a8285c5888486" rel="noreferrer noopener nofollow">[email protected]</a>
##### not working with tags
- !user { id: user1, annotations: { name: 'Louisa Nicolas', email: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bdd0dcd4d1fdd9d2d0dcd4d393ded2d0" rel="noreferrer noopener nofollow">[email protected]</a> } }
- !user { id: user2, annotations: { name: 'Telper Max', email: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c2afa3abae82a6adafa3abaceca1adaf" rel="noreferrer noopener nofollow">[email protected]</a> } }

我希望有标记

- !user 
  id: user1, 
  annotations: 
    name: 'Louisa Nicolas'
    email: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="036e626a6f43676c6e626a6d2d606c6e" rel="noreferrer noopener nofollow">[email protected]</a>
- !user
  id: user2
  annotations: 
    name: 'Telper Max'
    email: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e28f838b8ea2868d8f838b8ccc818d8f" rel="noreferrer noopener nofollow">[email protected]</a> 

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

Yaml dump : ignore inline parameter when TaggedValue used

最佳答案

错误已被批准。 3.4 版本已修复。

拉取请求 [Yaml] fix inline handling when dumping tagged values有实际的代码更改。

关于php - 使用 TaggedValue 时转储函数忽略内联参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56805201/

相关文章:

php - FBConnect:为什么它显示在某些页面上而不显示在其他页面上?

php - 通过 docker 容器邮件服务器在 Symfony 中发送电子邮件

symfony - 如何在 buildForm 函数中将 "selected"选项与用户区域设置一起使用?

amazon-web-services - 有没有办法有条件地将过期策略添加到 cloudformation 中的 S3 存储桶

symfony - JMS 序列化器 yml 日期时间格式

php - Javascript 等效于 php 的 $object->{$stringvar} = 1 没有 eval()?

php - 3D 数组 PHP 中的 MySQL 结果

php - GET 表单方法不会附加参数

php - Symfony2 : Unable to overwrite 'maxSize' and 'maxSizeMessage' in Image/File constraint

kubernetes - 入口端点在 GKE 上显示响应为 200 的空白页面