Skip to content

Commit f88d55e

Browse files
authored
Issue #389: Replace ProcessBuilder with Process in init command. (#390)
1 parent ab3abc2 commit f88d55e

File tree

1 file changed

+54
-47
lines changed

1 file changed

+54
-47
lines changed

src/Command/InitCommand.php

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Symfony\Component\Console\Input\InputOption;
1212
use Symfony\Component\Console\Output\OutputInterface;
1313
use Symfony\Component\Filesystem\Filesystem;
14-
use Symfony\Component\Process\ProcessBuilder;
14+
use Symfony\Component\Process\Process;
1515
use Symfony\Component\Finder\Finder;
1616
use Drupal\Console\Core\Utils\ConfigurationManager;
1717
use Drupal\Console\Core\Generator\InitGenerator;
@@ -24,6 +24,7 @@
2424
*/
2525
class InitCommand extends Command
2626
{
27+
2728
/**
2829
* @var ShowFile
2930
*/
@@ -49,30 +50,32 @@ class InitCommand extends Command
4950
*/
5051
protected $generator;
5152

52-
private $configParameters = [
53-
'language' => 'en',
54-
'temp' => '/tmp',
55-
'chain' => false,
56-
'sites' => false,
57-
'learning' => false,
58-
'generate_inline' => false,
59-
'generate_chain' => false,
60-
'statistics' => true
61-
];
62-
63-
private $directories = [
64-
'chain',
65-
'sites',
66-
];
53+
private $configParameters
54+
= [
55+
'language' => 'en',
56+
'temp' => '/tmp',
57+
'chain' => false,
58+
'sites' => false,
59+
'learning' => false,
60+
'generate_inline' => false,
61+
'generate_chain' => false,
62+
'statistics' => true,
63+
];
64+
65+
private $directories
66+
= [
67+
'chain',
68+
'sites',
69+
];
6770

6871
/**
6972
* InitCommand constructor.
7073
*
71-
* @param ShowFile $showFile
72-
* @param ConfigurationManager $configurationManager
73-
* @param InitGenerator $generator
74-
* @param string $appRoot
75-
* @param string $consoleRoot
74+
* @param ShowFile $showFile
75+
* @param ConfigurationManager $configurationManager
76+
* @param InitGenerator $generator
77+
* @param string $appRoot
78+
* @param string $consoleRoot
7679
*/
7780
public function __construct(
7881
ShowFile $showFile,
@@ -81,11 +84,11 @@ public function __construct(
8184
$appRoot,
8285
$consoleRoot = null
8386
) {
84-
$this->showFile = $showFile;
87+
$this->showFile = $showFile;
8588
$this->configurationManager = $configurationManager;
86-
$this->generator = $generator;
87-
$this->appRoot = $appRoot;
88-
$this->consoleRoot = $consoleRoot;
89+
$this->generator = $generator;
90+
$this->appRoot = $appRoot;
91+
$this->consoleRoot = $consoleRoot;
8992
parent::__construct();
9093
}
9194

@@ -128,13 +131,13 @@ protected function configure()
128131
*/
129132
protected function interact(InputInterface $input, OutputInterface $output)
130133
{
131-
$destination = $input->getOption('destination');
132-
$site = $input->getOption('site');
133-
$autocomplete = $input->getOption('autocomplete');
134+
$destination = $input->getOption('destination');
135+
$site = $input->getOption('site');
136+
$autocomplete = $input->getOption('autocomplete');
134137
$configuration = $this->configurationManager->getConfiguration();
135138

136139
if ($site && $this->appRoot && $this->consoleRoot) {
137-
$destination = $this->consoleRoot . '/console/';
140+
$destination = $this->consoleRoot.'/console/';
138141
}
139142

140143
if (!$destination) {
@@ -221,14 +224,14 @@ protected function interact(InputInterface $input, OutputInterface $output)
221224
*/
222225
protected function execute(InputInterface $input, OutputInterface $output)
223226
{
224-
$copiedFiles = [];
225-
$destination = $input->getOption('destination');
226-
$site = $input->getOption('site');
227+
$copiedFiles = [];
228+
$destination = $input->getOption('destination');
229+
$site = $input->getOption('site');
227230
$autocomplete = $input->getOption('autocomplete');
228-
$override = $input->getOption('override');
231+
$override = $input->getOption('override');
229232

230233
if ($site && $this->appRoot && $this->consoleRoot) {
231-
$destination = $this->consoleRoot . '/console/';
234+
$destination = $this->consoleRoot.'/console/';
232235
}
233236

234237
if (!$destination) {
@@ -282,34 +285,37 @@ protected function execute(InputInterface $input, OutputInterface $output)
282285

283286
$executableName = null;
284287
if ($autocomplete) {
285-
$processBuilder = new ProcessBuilder(['bash']);
286-
$process = $processBuilder->getProcess();
288+
$process = new Process(['bash']);
287289
$process->setCommandLine('echo $_');
288290
$process->run();
289291
$fullPathExecutable = explode('/', $process->getOutput());
290-
$executableName = trim(end($fullPathExecutable));
292+
$executableName = trim(end($fullPathExecutable));
291293
$process->stop();
292294
}
293295

294296
$this->generator->generate(
295297
[
296-
'user_home' => $this->configurationManager->getConsoleDirectory(),
297-
'executable_name' => $executableName,
298-
'override' => $override,
299-
'destination' => $destination,
300-
'config_parameters' => $this->configParameters,
298+
'user_home' => $this->configurationManager->getConsoleDirectory(
299+
),
300+
'executable_name' => $executableName,
301+
'override' => $override,
302+
'destination' => $destination,
303+
'config_parameters' => $this->configParameters,
301304
]
302305
);
303306

304-
$this->getIo()->writeln($this->trans('application.messages.autocomplete'));
307+
$this->getIo()->writeln(
308+
$this->trans('application.messages.autocomplete')
309+
);
305310

306311
return 0;
307312
}
308313

309314
/**
310-
* @param string $source
311-
* @param string $destination
312-
* @param string $override
315+
* @param string $source
316+
* @param string $destination
317+
* @param string $override
318+
*
313319
* @return bool
314320
*/
315321
private function copyFile($source, $destination, $override)
@@ -318,7 +324,7 @@ private function copyFile($source, $destination, $override)
318324
if ($override) {
319325
copy(
320326
$destination,
321-
$destination . '.old'
327+
$destination.'.old'
322328
);
323329
} else {
324330
return false;
@@ -335,4 +341,5 @@ private function copyFile($source, $destination, $override)
335341
$destination
336342
);
337343
}
344+
338345
}

0 commit comments

Comments
 (0)