ShinDarth ShinDarth - 20 days ago 5
YAML Question

Symfony Yaml component: how to always wrap string in quotes when using Yaml::dump

When using the Yaml::dump function of Symfony Yaml component, the output will have some strings wrapped by single quotes and other strings not wrapped at all.

I know that both wrapped and non-wrapped strings are correct in Yaml, but I was wondering if there was a way to standardize the ouput (e.g. setting strings always be wrapped by single or double quotes) in order to make it consistent.

Answer

According to the documentation, dump takes some flags. They are listed at the top of the documentation (without explanation):

  • DUMP_OBJECT
  • DUMP_EXCEPTION_ON_INVALID_TYPE
  • DUMP_OBJECT_AS_MAP
  • DUMP_MULTI_LINE_LITERAL_BLOCK

None of these have to do with quotation, so the answer is: No, it's not possible. Quotation is decided by the Escaper, which does not have any customization options.