3535use Symfony \Component \Console \Question \Question ;
3636
3737class SetConfig extends Base {
38- private InputInterface $ input ;
39- private OutputInterface $ output ;
40-
4138 public function __construct (
4239 protected IAppConfig $ appConfig ,
4340 ) {
@@ -97,8 +94,6 @@ protected function configure() {
9794 protected function execute (InputInterface $ input , OutputInterface $ output ): int {
9895 $ appName = $ input ->getArgument ('app ' );
9996 $ configName = $ input ->getArgument ('name ' );
100- $ this ->input = $ input ;
101- $ this ->output = $ output ;
10297
10398 if (!($ this ->appConfig instanceof AppConfig)) {
10499 throw new \Exception ('Only compatible with OC\AppConfig as it uses internal methods ' );
@@ -126,19 +121,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
126121 */
127122 $ updated = false ;
128123 if (!$ input ->hasParameterOption ('--value ' )) {
129- if (!$ input ->getOption ('lazy ' ) && $ this ->appConfig ->isLazy ($ appName , $ configName ) && $ this ->ask ('NOT LAZY ' )) {
124+ if (!$ input ->getOption ('lazy ' ) && $ this ->appConfig ->isLazy ($ appName , $ configName ) && $ this ->ask ($ input , $ output , 'NOT LAZY ' )) {
130125 $ updated = $ this ->appConfig ->updateLazy ($ appName , $ configName , false );
131126 }
132- if ($ input ->getOption ('lazy ' ) && !$ this ->appConfig ->isLazy ($ appName , $ configName ) && $ this ->ask ('LAZY ' )) {
127+ if ($ input ->getOption ('lazy ' ) && !$ this ->appConfig ->isLazy ($ appName , $ configName ) && $ this ->ask ($ input , $ output , 'LAZY ' )) {
133128 $ updated = $ this ->appConfig ->updateLazy ($ appName , $ configName , true ) || $ updated ;
134129 }
135- if (!$ input ->getOption ('sensitive ' ) && $ this ->appConfig ->isSensitive ($ appName , $ configName ) && $ this ->ask ('NOT SENSITIVE ' )) {
130+ if (!$ input ->getOption ('sensitive ' ) && $ this ->appConfig ->isSensitive ($ appName , $ configName ) && $ this ->ask ($ input , $ output , 'NOT SENSITIVE ' )) {
136131 $ updated = $ this ->appConfig ->updateSensitive ($ appName , $ configName , false ) || $ updated ;
137132 }
138- if ($ input ->getOption ('sensitive ' ) && !$ this ->appConfig ->isSensitive ($ appName , $ configName ) && $ this ->ask ('SENSITIVE ' )) {
133+ if ($ input ->getOption ('sensitive ' ) && !$ this ->appConfig ->isSensitive ($ appName , $ configName ) && $ this ->ask ($ input , $ output , 'SENSITIVE ' )) {
139134 $ updated = $ this ->appConfig ->updateSensitive ($ appName , $ configName , true ) || $ updated ;
140135 }
141- if ($ typeString !== null && $ type !== $ this ->appConfig ->getValueType ($ appName , $ configName ) && $ this ->ask ($ typeString )) {
136+ if ($ type !== null && $ type !== $ this ->appConfig ->getValueType ($ appName , $ configName ) && $ typeString !== null && $ this ->ask ($ input , $ output , $ typeString )) {
142137 $ updated = $ this ->appConfig ->updateType ($ appName , $ configName , $ type ) || $ updated ;
143138 }
144139 } else {
@@ -149,7 +144,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
149144 */
150145 try {
151146 $ currType = $ this ->appConfig ->getValueType ($ appName , $ configName );
152- if ($ type === null || $ type === $ currType || !$ this ->ask ($ typeString )) {
147+ if ($ typeString === null || $ type === $ currType || !$ this ->ask ($ input , $ output , $ typeString )) {
153148 $ type = $ currType ;
154149 } else {
155150 $ updated = $ this ->appConfig ->updateType ($ appName , $ configName , $ type );
@@ -166,7 +161,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
166161 $ lazy = $ input ->getOption ('lazy ' );
167162 try {
168163 $ currLazy = $ this ->appConfig ->isLazy ($ appName , $ configName );
169- if ($ lazy === null || $ lazy === $ currLazy || !$ this ->ask (($ lazy ) ? 'LAZY ' : 'NOT LAZY ' )) {
164+ if ($ lazy === null || $ lazy === $ currLazy || !$ this ->ask ($ input , $ output , ($ lazy ) ? 'LAZY ' : 'NOT LAZY ' )) {
170165 $ lazy = $ currLazy ;
171166 }
172167 } catch (AppConfigUnknownKeyException ) {
@@ -179,7 +174,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
179174 $ sensitive = $ input ->getOption ('sensitive ' );
180175 try {
181176 $ currSensitive = $ this ->appConfig ->isLazy ($ appName , $ configName );
182- if ($ sensitive === null || $ sensitive === $ currSensitive || !$ this ->ask (($ sensitive ) ? 'LAZY ' : 'NOT LAZY ' )) {
177+ if ($ sensitive === null || $ sensitive === $ currSensitive || !$ this ->ask ($ input , $ output , ($ sensitive ) ? 'LAZY ' : 'NOT LAZY ' )) {
183178 $ sensitive = $ currSensitive ;
184179 }
185180 } catch (AppConfigUnknownKeyException ) {
@@ -249,26 +244,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int
249244 return 0 ;
250245 }
251246
252- private function ask (string $ request ): bool {
247+ private function ask (InputInterface $ input , OutputInterface $ output , string $ request ): bool {
253248 $ helper = $ this ->getHelper ('question ' );
254- if ($ this -> input ->getOption ('no-interaction ' )) {
249+ if ($ input ->getOption ('no-interaction ' )) {
255250 return true ;
256251 }
257252
258- $ this -> output ->writeln (sprintf ('You are about to set config value %s as <info>%s</info> ' ,
259- '<info> ' . $ this -> input ->getArgument ('app ' ) . '</info>/<info> ' . $ this -> input ->getArgument ('name ' ) . '</info> ' ,
253+ $ output ->writeln (sprintf ('You are about to set config value %s as <info>%s</info> ' ,
254+ '<info> ' . $ input ->getArgument ('app ' ) . '</info>/<info> ' . $ input ->getArgument ('name ' ) . '</info> ' ,
260255 strtoupper ($ request )
261256 ));
262- $ this -> output ->writeln ('' );
263- $ this -> output ->writeln ('<comment>This might break thing, affect performance on your instance or its security!</comment> ' );
257+ $ output ->writeln ('' );
258+ $ output ->writeln ('<comment>This might break thing, affect performance on your instance or its security!</comment> ' );
264259
265260 $ result = (strtolower ((string )$ helper ->ask (
266- $ this -> input ,
267- $ this -> output ,
261+ $ input ,
262+ $ output ,
268263 new Question ('<comment>Confirm this action by typing \'yes \'</comment>: ' ))) === 'yes ' );
269264
270- $ this -> output ->writeln (($ result ) ? 'done ' : 'cancelled ' );
271- $ this -> output ->writeln ('' );
265+ $ output ->writeln (($ result ) ? 'done ' : 'cancelled ' );
266+ $ output ->writeln ('' );
272267
273268 return $ result ;
274269 }
0 commit comments