Neos\Flow\Configuration\Source\YamlSource::save PHP Method

save() public method

Save the specified configuration array to the given file in YAML format.
public save ( string $pathAndFilename, array $configuration ) : void
$pathAndFilename string Full path and filename of the file to write to, excluding the dot and file extension (i.e. ".yaml")
$configuration array The configuration to save
return void
    public function save($pathAndFilename, array $configuration)
    {
        $header = '';
        if (file_exists($pathAndFilename . '.yaml')) {
            $header = $this->getHeaderFromFile($pathAndFilename . '.yaml');
        }
        $yaml = Yaml::dump($configuration, 99, 2);
        file_put_contents($pathAndFilename . '.yaml', $header . chr(10) . $yaml);
    }

Usage Example

 /**
  * @test
  */
 public function saveDoesNotOverwriteExistingHeaderCommentsIfFileExists()
 {
     $pathAndFilename = vfsStream::url('testDirectory') . '/YAMLConfiguration';
     $comment = '# This comment should stay' . chr(10) . 'Test: foo' . chr(10);
     file_put_contents($pathAndFilename . '.yaml', $comment);
     $configurationSource = new YamlSource();
     $configurationSource->save($pathAndFilename, ['configurationFileHasBeenLoaded' => true]);
     $yaml = file_get_contents($pathAndFilename . '.yaml');
     $this->assertContains('# This comment should stay' . chr(10) . chr(10), $yaml, 'Header comment was removed from file.');
     $this->assertNotContains('Test: foo', $yaml);
 }
All Usage Examples Of Neos\Flow\Configuration\Source\YamlSource::save