11
11
use Symfony \Component \Console \Input \InputOption ;
12
12
use Symfony \Component \Console \Output \OutputInterface ;
13
13
use Symfony \Component \Filesystem \Filesystem ;
14
- use Symfony \Component \Process \ProcessBuilder ;
14
+ use Symfony \Component \Process \Process ;
15
15
use Symfony \Component \Finder \Finder ;
16
16
use Drupal \Console \Core \Utils \ConfigurationManager ;
17
17
use Drupal \Console \Core \Generator \InitGenerator ;
24
24
*/
25
25
class InitCommand extends Command
26
26
{
27
+
27
28
/**
28
29
* @var ShowFile
29
30
*/
@@ -49,30 +50,32 @@ class InitCommand extends Command
49
50
*/
50
51
protected $ generator ;
51
52
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
+ ];
67
70
68
71
/**
69
72
* InitCommand constructor.
70
73
*
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
76
79
*/
77
80
public function __construct (
78
81
ShowFile $ showFile ,
@@ -81,11 +84,11 @@ public function __construct(
81
84
$ appRoot ,
82
85
$ consoleRoot = null
83
86
) {
84
- $ this ->showFile = $ showFile ;
87
+ $ this ->showFile = $ showFile ;
85
88
$ 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 ;
89
92
parent ::__construct ();
90
93
}
91
94
@@ -128,13 +131,13 @@ protected function configure()
128
131
*/
129
132
protected function interact (InputInterface $ input , OutputInterface $ output )
130
133
{
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 ' );
134
137
$ configuration = $ this ->configurationManager ->getConfiguration ();
135
138
136
139
if ($ site && $ this ->appRoot && $ this ->consoleRoot ) {
137
- $ destination = $ this ->consoleRoot . '/console/ ' ;
140
+ $ destination = $ this ->consoleRoot . '/console/ ' ;
138
141
}
139
142
140
143
if (!$ destination ) {
@@ -221,14 +224,14 @@ protected function interact(InputInterface $input, OutputInterface $output)
221
224
*/
222
225
protected function execute (InputInterface $ input , OutputInterface $ output )
223
226
{
224
- $ copiedFiles = [];
225
- $ destination = $ input ->getOption ('destination ' );
226
- $ site = $ input ->getOption ('site ' );
227
+ $ copiedFiles = [];
228
+ $ destination = $ input ->getOption ('destination ' );
229
+ $ site = $ input ->getOption ('site ' );
227
230
$ autocomplete = $ input ->getOption ('autocomplete ' );
228
- $ override = $ input ->getOption ('override ' );
231
+ $ override = $ input ->getOption ('override ' );
229
232
230
233
if ($ site && $ this ->appRoot && $ this ->consoleRoot ) {
231
- $ destination = $ this ->consoleRoot . '/console/ ' ;
234
+ $ destination = $ this ->consoleRoot . '/console/ ' ;
232
235
}
233
236
234
237
if (!$ destination ) {
@@ -282,34 +285,37 @@ protected function execute(InputInterface $input, OutputInterface $output)
282
285
283
286
$ executableName = null ;
284
287
if ($ autocomplete ) {
285
- $ processBuilder = new ProcessBuilder (['bash ' ]);
286
- $ process = $ processBuilder ->getProcess ();
288
+ $ process = new Process (['bash ' ]);
287
289
$ process ->setCommandLine ('echo $_ ' );
288
290
$ process ->run ();
289
291
$ fullPathExecutable = explode ('/ ' , $ process ->getOutput ());
290
- $ executableName = trim (end ($ fullPathExecutable ));
292
+ $ executableName = trim (end ($ fullPathExecutable ));
291
293
$ process ->stop ();
292
294
}
293
295
294
296
$ this ->generator ->generate (
295
297
[
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 ,
301
304
]
302
305
);
303
306
304
- $ this ->getIo ()->writeln ($ this ->trans ('application.messages.autocomplete ' ));
307
+ $ this ->getIo ()->writeln (
308
+ $ this ->trans ('application.messages.autocomplete ' )
309
+ );
305
310
306
311
return 0 ;
307
312
}
308
313
309
314
/**
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
+ *
313
319
* @return bool
314
320
*/
315
321
private function copyFile ($ source , $ destination , $ override )
@@ -318,7 +324,7 @@ private function copyFile($source, $destination, $override)
318
324
if ($ override ) {
319
325
copy (
320
326
$ destination ,
321
- $ destination . '.old '
327
+ $ destination. '.old '
322
328
);
323
329
} else {
324
330
return false ;
@@ -335,4 +341,5 @@ private function copyFile($source, $destination, $override)
335
341
$ destination
336
342
);
337
343
}
344
+
338
345
}
0 commit comments