What is the best way to update a YAML file in PHP?
Currently I'm using the Symfony YAML component, and my code is as follows (note that $blueprint is the data from the YAML file). It works, but I'm not sure of its elegance.
function update\\_blueprint($path, $data = []) {
// Get existing data
$blueprint = get\\\_blueprint($path);
// loop over the data and overwrite or create data
foreach($data as $key => $val) {
$blueprint->$key = $val;
}
$blueprint = (array) $blueprint;
$yaml = \Symfony\Component\Yaml\Yaml::dump($blueprint);
$data = '---' . "\n";
$data .= $yaml;
$data .= '---';
$file = EMILIA\\\_DIR . '/\\\_site/blueprints/' . $path . '.yml';
file\\\_put\\\_contents($file, $data);
return true;
}