diff --git a/README.md b/README.md index 186b846c91..142c5cb567 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,10 @@ playing with it, you can remove it by following these steps: `security.firewalls.secured_area` entries in the `security.yml` file or tweak the security configuration to fit your needs. +Or use the following command : + ``` php app/console acme:bundle:remove ``` + + What's inside? --------------- diff --git a/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php b/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php new file mode 100644 index 0000000000..c330e3c3de --- /dev/null +++ b/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php @@ -0,0 +1,207 @@ +setName('acme:bundle:remove') + ->setDescription('Remove the Acme Demo Bundle') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $rootDir = $this->getContainer()->get('kernel')->getRootDir(); + $securityConfig = $rootDir. '/config/security.yml'; + $routingConfig = $rootDir. '/config/routing_dev.yml'; + $appKernel = $rootDir. '/AppKernel.php'; + + + $config = array('routing_dev' => file_get_contents($routingConfig), + 'security' => file_get_contents($securityConfig)); + + if ($this->hasDefaultsConfigChanged($config)) { + $output->writeln("This couldn't be performed, your config files have changed. You must remove the bundle manually"); + return; + } + + file_put_contents($securityConfig, $this->getBaseSecurityConfig()); + file_put_contents($routingConfig, $this->getBaseRoutingDevConfig()); + file_put_contents($appKernel, str_replace('$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();', '', file_get_contents($appKernel))); + + $fs = new Filesystem(); + try { + $fs->remove(array($rootDir.'/../src/Acme/')); + } catch (IOException $e) { + $output->writeln("An error occurred while removing the AcmeDemoBundle directory"); + return; + } + + $output->writeln("Acme Bundle has been removed successfully"); + } + + protected function getBaseSecurityConfig() + { + return +<<getDefaultRoutingDevConfig()) { + return true; + } + if (trim($config['security']) !== $this->getDefaultSecurityConfig()) { + return true; + } + + return false; + } +}