public function saveAs($filename, $format = 'auto')
    {

        if ($format === 'auto') {
            $format =   strtolower(substr($filename, -5)) === '.json' ? 'json' : 'yaml';
        }
        if (strtolower($format) === 'json') {
            $content = $this->toJson();
        } else {
            $content = $this->toYaml();
        }
        if (file_put_contents($filename, $content) === false) {
            throw new Exception('Failed to saveAs("' . $filename . '", "'.$format.'")');
        }
    }