我对 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>
我在支持团队中为此打开了一个错误,并且该错误已得到确认。
最佳答案
错误已被批准。 3.4 版本已修复。
拉取请求 [Yaml] fix inline handling when dumping tagged values有实际的代码更改。
关于php - 使用 TaggedValue 时转储函数忽略内联参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56805201/