Phpro\SoapClient\Util\Filesystem::createBackup PHP Method

createBackup() public method

public createBackup ( string $file )
$file string
    public function createBackup($file)
    {
        if (!$this->fileExists($file)) {
            throw new RunTimeException('Could not create a backup from a non existing file: ' . $file);
        }
        $backupFile = preg_replace('{\\.backup$}', '', $file) . '.backup';
        copy($file, $backupFile);
    }

Usage Example

 /**
  * This method tries to patch an existing type class.
  *
  * @param TypeGenerator   $generator
  * @param Type            $type
  * @param string          $path
  *
  * @return bool
  */
 protected function patchExistingFile(TypeGenerator $generator, Type $type, $path)
 {
     try {
         $this->filesystem->createBackup($path);
         $file = FileGenerator::fromReflectedFileName($path);
         $this->generateType($file, $generator, $type, $path);
     } catch (\Exception $e) {
         $this->output->writeln('<fg=red>' . $e->getMessage() . '</fg=red>');
         $this->filesystem->removeBackup($path);
         return false;
     }
     return true;
 }