public function addParameterToFile($filename, $name, $value, $preserveFormatting, $addComment = null)
    {
        $content = file_get_contents($filename);
        $data = Yaml::parse($content);

        if ($preserveFormatting) {
            $content = rtrim($content);

            $c = Yaml::dump(array(
                'parameters' => array(
                    $name => $value,
                ),
            ), 99);

            list(, $c) = explode("\n", $c, 2);

            if (!empty($addComment)) {
                $lines = explode("\n", trim($addComment));
                $lines = array_map(function($line) {
                    return '    # '.trim($line);
                }, $lines);

                $content .= "\n\n".implode("\n", $lines);
            }
            $content .= "\n".$c;
        } else {
            $data['parameters'][$name] = $value;
            $content = Yaml::dump($data, 99);
        }

        file_put_contents($filename, $content);
    }