public function writeFile($filename, $contents, $backup = true)
    {
        $fs = new SymfonyFilesystem();
        if (file_exists($filename) && $backup && $contents !== file_get_contents($filename)) {
            $backupName = dirname($filename) . '/' . basename($filename) . '.bak';
            $fs->rename($filename, $backupName, true);
        }
        $fs->dumpFile($filename, $contents);
    }
public function writeFile($filename, $contents, $backup = true)
    {
        $fs = new SymfonyFilesystem();
        if (file_exists($filename) && $backup && $contents !== file_get_contents($filename)) {
            $backupName = dirname($filename) . '/' . basename($filename) . '.bak';
            $fs->rename($filename, $backupName, true);
        }
        $fs->dumpFile($filename, $contents);
    }
public function writeFile ( $ filename , $ contents , $ backup = true ) { $ fs = new SymfonyFilesystem ( ) ; if ( file_exists ( $ filename ) && $ backup && $ contents !== file_get_contents ( $ filename ) ) { $ backupName = dirname ( $ filename ) . '/' . basename ( $ filename ) . '.bak' ; $ fs -> rename ( $ filename , $ backupName , true ) ; } $ fs -> dumpFile ( $ filename , $ contents ) ; }
Write a file and create a backup if the contents have changed.

@param string $filename
@param string $contents
@param bool   $backup
Write a file and create a backup if the contents have changed .