5 * Contains \Drupal\Console\Core\Command\GenerateCommand.
8 namespace Drupal\Console\Core\Command;
10 use Symfony\Component\Filesystem\Filesystem;
11 use Webmozart\PathUtil\Path;
14 * Class GenerateCommand
16 * @package Drupal\Console\Core\Command
18 abstract class GenerateCommand extends Command
20 protected function validateFileExists(
23 $stopOnException = true
26 if (!is_array($sourceFiles)) {
27 $sourceFiles = [$sourceFiles];
29 foreach ($sourceFiles as $sourceFile) {
30 if ($fs->exists($sourceFile)) {
34 $notFound[] = Path::makeRelative(
36 $this->drupalFinder->getComposerRoot()
40 if ($stopOnException) {
41 $this->createException(
42 'File(s): ' . implode(', ', $notFound) . ' not found.'
49 protected function backUpFile(Filesystem $fs, $fileName)
51 $fileNameBackup = $fileName.'.original';
52 if ($fs->exists($fileName)) {
53 if ($fs->exists($fileNameBackup)) {
54 $fs->remove($fileName);
64 $fileNameBackup = Path::makeRelative(
66 $this->drupalFinder->getComposerRoot()
69 $this->getIo()->success(
70 'File ' . $fileNameBackup . ' created.'
76 protected function showFileCreatedMessage($fileName) {
77 $fileName = Path::makeRelative(
79 $this->drupalFinder->getComposerRoot()
82 $this->getIo()->success('File: ' . $fileName . ' created.');