@@ -356,6 +356,16 @@ public function offsetUnset($name)
356356 unset($ this ->helpers [$ name ]);
357357 }
358358
359+ public static function proceedTask (&$ flags , $ io , $ taskResult , $ flag , $ successMessage , $ message )
360+ {
361+ if ($ taskResult ) {
362+ $ flags |= $ flag ;
363+ $ message = $ successMessage ;
364+ }
365+
366+ $ io ->write ($ message );
367+ }
368+
359369 public static function install ($ event , $ dir = null )
360370 {
361371 /** @var \Composer\Script\Event $event */
@@ -387,6 +397,10 @@ public static function install($event, $dir = null)
387397 $ addConfig = $ io ->askConfirmation ('Would you like us to add automatically needed settings in your config.yml? [Y/N] ' );
388398 $ addBundle = $ io ->askConfirmation ('Would you like us to add automatically the pug bundle in your AppKernel.php? [Y/N] ' );
389399
400+ $ proceedTask = function ($ taskResult , $ flag , $ successMessage , $ errorMessage ) use (&$ flags , $ io ) {
401+ static ::proceedTask ($ flags , $ io , $ taskResult , $ flag , $ successMessage , $ errorMessage );
402+ };
403+
390404 if ($ addConfig ) {
391405 $ configFile = $ dir . '/app/config/config.yml ' ;
392406 $ contents = @file_get_contents ($ configFile ) ?: '' ;
@@ -397,12 +411,12 @@ public static function install($event, $dir = null)
397411 $ contents = preg_replace ('/^framework\s*:/m ' , "services: \n\$0 " , $ contents );
398412 }
399413 $ contents = preg_replace ('/^services\s*:/m ' , "\$0 $ service " , $ contents );
400- if ( file_put_contents ( $ configFile , $ contents )) {
401- $ flags |= static :: CONFIG_OK ;
402- $ io -> write ( ' Engine service added in config.yml ' );
403- } else {
404- $ io -> write ( 'Unable to add the engine service in config.yml ' );
405- }
414+ $ proceedTask (
415+ file_put_contents ( $ configFile , $ contents ),
416+ static :: CONFIG_OK ,
417+ ' Engine service added in config.yml ' ,
418+ 'Unable to add the engine service in config.yml '
419+ );
406420 } else {
407421 $ flags |= static ::CONFIG_OK ;
408422 $ io ->write ('templating.engine.pug setting in config.yml already exists. ' );
@@ -452,12 +466,12 @@ public static function install($event, $dir = null)
452466 }
453467 if ($ proceeded ) {
454468 $ contents = implode ("\n" , $ lines );
455- if ( file_put_contents ( $ configFile , $ contents )) {
456- $ flags |= static :: ENGINE_OK ;
457- $ io -> write ( ' Engine added to framework.templating.engines in config.yml ' );
458- } else {
459- $ io -> write ( 'Unable to add the templating engine in framework.templating.engines in config.yml ' );
460- }
469+ $ proceedTask (
470+ file_put_contents ( $ configFile , $ contents ),
471+ static :: ENGINE_OK ,
472+ ' Engine added to framework.templating.engines in config.yml ' ,
473+ 'Unable to add the templating engine in framework.templating.engines in config.yml '
474+ );
461475 }
462476 } else {
463477 $ io ->write ('framework entry not found in config.yml. ' );
@@ -473,12 +487,12 @@ public static function install($event, $dir = null)
473487 if (preg_match ('/^[ \\t]*new \\s+Symfony \\\\Bundle \\\\FrameworkBundle \\\\FrameworkBundle \\( \\)/m ' , $ contents )) {
474488 if (strpos ($ contents , $ bundle ) === false ) {
475489 $ contents = preg_replace ('/^([ \\t]*)new \\s+Symfony \\\\Bundle \\\\FrameworkBundle \\\\FrameworkBundle \\( \\)/m ' , "\$0, \n\$1 $ bundle " , $ contents );
476- if ( file_put_contents ( $ appFile , $ contents )) {
477- $ flags |= static :: KERNEL_OK ;
478- $ io -> write ( ' Bundle added to AppKernel.php ' );
479- } else {
480- $ io -> write ( 'Unable to add the bundle engine in AppKernel.php ' );
481- }
490+ $ proceedTask (
491+ file_put_contents ( $ appFile , $ contents ),
492+ static :: KERNEL_OK ,
493+ ' Bundle added to AppKernel.php ' ,
494+ 'Unable to add the bundle engine in AppKernel.php '
495+ );
482496 } else {
483497 $ flags |= static ::KERNEL_OK ;
484498 $ io ->write ('The bundle already exists in AppKernel.php ' );
0 commit comments