/** * @param string $original * @param string $new * @param string $patchFile * * @return string */ protected function createPatch($original, $new, $patchFile) { $process = ProcessBuilder::create(['diff', '-uN', $new, $original])->setWorkingDirectory($this->tmpFolder)->getProcess(); $process->run(); if (!$process->isSuccessful() && $process->getExitCode() !== 1) { throw new PatchException('Diff failed: ' . $process->getOutput()); } $patchData = $process->getOutput(); $this->filesystem->putFileContents($patchFile, $patchData); return $patchData; }
/** * @param InputInterface $input * @param OutputInterface $output * @param string $file * @param string $name * @param string $newContent */ protected function handleExistingFile(InputInterface $input, OutputInterface $output, $file, $name, $newContent) { // Patch the file $patched = $this->patchExistingFile($output, $file, $newContent); if ($patched) { $output->writeln('Patched!'); return; } $output->writeln('Could not patch.'); // Ask for overwriting the file: $allowOverwrite = $this->askForOverwrite($input, $output, $newContent); if (!$allowOverwrite) { $output->writeln(sprintf('Skipping %s', $name)); return; } // Overwrite $this->filesystem->putFileContents($file, $newContent); }
/** * Generates one type class * * @param FileGenerator $file * @param TypeGenerator $generator * @param Type $type * @param string $path */ protected function generateType(FileGenerator $file, TypeGenerator $generator, Type $type, $path) { $code = $generator->generate($file, $type); $this->filesystem->putFileContents($path, $code); }