Skip to content

Commit f118cad

Browse files
committed
Move extension root condition to BaseGenerator class.
1 parent 6381349 commit f118cad

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/Command/BaseGenerator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ protected function configure() {
100100
protected function initialize(InputInterface $input, OutputInterface $output) {
101101
$this->getHelperSet()->setCommand($this);
102102
$this->getHelper('dcg_renderer')->addPath($this->templatePath);
103-
$this->directory = $input->getOption('directory') ?
104-
Utils::normalizePath($input->getOption('directory')) : getcwd();
103+
104+
$directory_option = $input->getOption('directory');
105+
$directory = $directory_option ? Utils::normalizePath($directory_option) : getcwd();
106+
$this->directory = Utils::getExtensionRoot($directory) ?: $directory;
105107
}
106108

107109
/**

src/Helper/Dumper.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ class Dumper extends Helper {
2222
*/
2323
public $filesystem;
2424

25-
/**
26-
* The base directory.
27-
*
28-
* @var string
29-
*/
30-
protected $baseDirectory;
31-
3225
/**
3326
* Input instance.
3427
*
@@ -97,11 +90,7 @@ public function dump(InputInterface $input, OutputInterface $output) {
9790
/** @var \DrupalCodeGenerator\Command\GeneratorInterface $command */
9891
$command = $this->getHelperSet()->getCommand();
9992

100-
$directory = $command->getDirectory();
101-
$extension_root = Utils::getExtensionRoot($directory);
102-
$this->baseDirectory = ($extension_root ?: $directory) . '/';
103-
104-
$dumped_files = $this->doDump($command->getFiles());
93+
$dumped_files = $this->doDump($command->getFiles(), $command->getDirectory());
10594

10695
$input->setInteractive($interactive);
10796
return $dumped_files;
@@ -112,11 +101,13 @@ public function dump(InputInterface $input, OutputInterface $output) {
112101
*
113102
* @param array $files
114103
* Files to dump.
104+
* @param string $directory
105+
* Directory where to dump the files.
115106
*
116107
* @return array
117108
* List of created or updated files.
118109
*/
119-
protected function doDump(array $files) {
110+
protected function doDump(array $files, $directory) {
120111
$dumped_files = [];
121112

122113
foreach ($files as $file_name => $file_info) {
@@ -126,7 +117,7 @@ protected function doDump(array $files) {
126117

127118
$is_directory = $content === NULL;
128119

129-
$file_path = $this->baseDirectory . $file_name;
120+
$file_path = $directory . '/' . $file_name;
130121
if ($this->filesystem->exists($file_path) && !$is_directory) {
131122
$action = isset($file_info['action']) ? $file_info['action'] : 'replace';
132123
if ($action == 'replace') {

0 commit comments

Comments
 (0)