Skip to content

[Yaml] Allow to generate (dump) Yaml anchors and aliasses #62648

@gisostallenberg

Description

@gisostallenberg

Description

I want the output of Yaml::dump to understand anchors and aliasses.

Suggested possibility:

$data = [
  'key' => new \Symfony\Component\Yaml\Anchor\Anchor('anchor_name', [
    'sub' => 'data',
    '<<' => new Symfony\Component\Yaml\Anchor\Alias( 'anchor_name'),
  ]),
];
key: &anchor_name
  sub: 'data'
  <<: *anchor_name

This example is not complete, but just a simple example of the requested feature.

I'm happy to start a PR if you are interested in this feature (which I really would like to use).

An alternative approach would be to add a Literal/Raw class, which is just output-as-is, for both keys (not sure how to have an array key for this, yet) and values, which would allow developers to insert structures that actually are valid yaml, but cannot be used right now.

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions