1111use Symfony \Component \Console \Input \InputInterface ;
1212use Symfony \Component \Console \Output \OutputInterface ;
1313use Symfony \Component \Filesystem \Filesystem ;
14- use Symfony \Component \Process \ProcessBuilder ;
14+ use Symfony \Component \Process \Process ;
1515use Symfony \Component \Yaml \Parser ;
1616use Symfony \Component \Filesystem \Exception \IOExceptionInterface ;
1717use Drupal \Component \Serialization \Yaml ;
2222
2323class EditCommand extends Command
2424{
25+
2526 /**
2627 * @var ConfigFactory
2728 */
@@ -40,20 +41,21 @@ class EditCommand extends Command
4041 /**
4142 * EditCommand constructor.
4243 *
43- * @param ConfigFactory $configFactory
44- * @param CachedStorage $configStorage
45- * @param ConfigurationManager $configurationManager
44+ * @param ConfigFactory $configFactory
45+ * @param CachedStorage $configStorage
46+ * @param ConfigurationManager $configurationManager
4647 */
4748 public function __construct (
4849 ConfigFactory $ configFactory ,
4950 CachedStorage $ configStorage ,
5051 ConfigurationManager $ configurationManager
5152 ) {
52- $ this ->configFactory = $ configFactory ;
53- $ this ->configStorage = $ configStorage ;
53+ $ this ->configFactory = $ configFactory ;
54+ $ this ->configStorage = $ configStorage ;
5455 $ this ->configurationManager = $ configurationManager ;
5556 parent ::__construct ();
5657 }
58+
5759 /**
5860 * {@inheritdoc}
5961 */
@@ -80,34 +82,42 @@ protected function configure()
8082 */
8183 protected function execute (InputInterface $ input , OutputInterface $ output )
8284 {
83- $ configName = $ input ->getArgument ('config-name ' );
84- $ editor = $ input ->getArgument ('editor ' );
85- $ config = $ this ->configFactory ->getEditable ($ configName );
86- $ configSystem = $ this ->configFactory ->get ('system.file ' );
85+ $ configName = $ input ->getArgument ('config-name ' );
86+ $ editor = $ input ->getArgument ('editor ' );
87+ $ config = $ this ->configFactory ->getEditable ($ configName );
88+ $ configSystem = $ this ->configFactory ->get ('system.file ' );
8789 $ temporaryDirectory = $ configSystem ->get ('path.temporary ' ) ?: '/tmp ' ;
88- $ configFile = $ temporaryDirectory .'/config-edit/ ' .$ configName .'.yml ' ;
89- $ ymlFile = new Parser ();
90- $ fileSystem = new Filesystem ();
90+ $ configFile = $ temporaryDirectory .'/config-edit/ ' .$ configName
91+ .'.yml ' ;
92+ $ ymlFile = new Parser ();
93+ $ fileSystem = new Filesystem ();
9194
9295 if (!$ configName ) {
93- $ this ->getIo ()->error ($ this ->trans ('commands.config.edit.messages.no-config ' ));
96+ $ this ->getIo ()->error (
97+ $ this ->trans ('commands.config.edit.messages.no-config ' )
98+ );
9499
95100 return 1 ;
96101 }
97102
98103 try {
99104 $ fileSystem ->mkdir ($ temporaryDirectory );
100- $ fileSystem ->dumpFile ($ configFile , $ this ->getYamlConfig ($ configName ));
105+ $ fileSystem ->dumpFile (
106+ $ configFile ,
107+ $ this ->getYamlConfig ($ configName )
108+ );
101109 } catch (IOExceptionInterface $ e ) {
102- $ this ->getIo ()->error ($ this ->trans ('commands.config.edit.messages.no-directory ' ).' ' .$ e ->getPath ());
110+ $ this ->getIo ()->error (
111+ $ this ->trans ('commands.config.edit.messages.no-directory ' ).' '
112+ .$ e ->getPath ()
113+ );
103114
104115 return 1 ;
105116 }
106117 if (!$ editor ) {
107118 $ editor = $ this ->getEditor ();
108119 }
109- $ processBuilder = new ProcessBuilder ([$ editor , $ configFile ]);
110- $ process = $ processBuilder ->getProcess ();
120+ $ process = new Process ([$ editor , $ configFile ]);
111121 $ process ->setTty ('true ' );
112122 $ process ->run ();
113123
@@ -120,6 +130,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
120130
121131 if (!$ process ->isSuccessful ()) {
122132 $ this ->getIo ()->error ($ process ->getErrorOutput ());
133+
123134 return 1 ;
124135 }
125136
@@ -131,8 +142,10 @@ protected function interact(InputInterface $input, OutputInterface $output)
131142 $ configName = $ input ->getArgument ('config-name ' );
132143 if (!$ configName ) {
133144 $ configNames = $ this ->configFactory ->listAll ();
134- $ configName = $ this ->getIo ()->choice (
135- $ this ->trans ('commands.config.edit.messages.choose-configuration ' ),
145+ $ configName = $ this ->getIo ()->choice (
146+ $ this ->trans (
147+ 'commands.config.edit.messages.choose-configuration '
148+ ),
136149 $ configNames
137150 );
138151
@@ -148,7 +161,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
148161 protected function getYamlConfig ($ config_name )
149162 {
150163 if ($ this ->configStorage ->exists ($ config_name )) {
151- $ configuration = $ this ->configStorage ->read ($ config_name );
164+ $ configuration = $ this ->configStorage ->read ($ config_name );
152165 $ configurationEncoded = Yaml::encode ($ configuration );
153166 }
154167
@@ -167,13 +180,13 @@ protected function getEditor()
167180 return trim ($ editor );
168181 }
169182
170- $ processBuilder = new ProcessBuilder (['bash ' ]);
171- $ process = $ processBuilder ->getProcess ();
172- $ process ->setCommandLine ('echo ${EDITOR:-${VISUAL:-vi}} ' );
183+ $ process = new Process (['bash ' ]);
184+ $ process ->setCommandLine ('echo ${EDITOR:-${VISUAL:-nano}} ' );
173185 $ process ->run ();
174186 $ editor = $ process ->getOutput ();
175187 $ process ->stop ();
176188
177189 return trim ($ editor );
178190 }
191+
179192}
0 commit comments