user3803850
user3803850

Reputation: 9937

How can i add some key values in existing yaml file in php symfony

I have one YAML file like this

  category: 'test'
  available: true
  class: true
  name: 'john'
  children:
    -
      id: fdfd5
      f2: 30

Now before that name field i want to add one more file like

displayname = This is your $name where $name is name from same category.

This is what i am thinkling of

//read
$yaml = Yaml::parse(file_get_contents('/path/to/file.yml'));


//code here    

//write
$dumper = new Dumper();

$yaml = $dumper->dump($array);

file_put_contents('/path/to/file.yml', $yaml);

How can i get $array to what i want

Upvotes: 0

Views: 1516

Answers (1)

Peter Bailey
Peter Bailey

Reputation: 105878

Uh, I think this will work (don't have a VM nearby so I can't test it)

$yaml = array_merge(
    array('displayname' => "This is your $name")
  , Yaml::parse(file_get_contents('/path/to/file.yml'))
);

file_put_contents('/path/to/file.yml', Yaml::dump($yaml));

Or you could always make your own configuration class

Upvotes: 1

Related Questions