diff --git a/UPGRADE-2.2.md b/UPGRADE-2.2.md index d4b47d17e8..c10fedcd4c 100644 --- a/UPGRADE-2.2.md +++ b/UPGRADE-2.2.md @@ -9,3 +9,21 @@ Functional Tests even better, you can just enable it for the very next request by calling ``$client->enableProfiler()`` when you need the profiler in a test (that speeds up functional tests quite a bit). + +Routing +---------------- + * The default place for Acme DemoBundle routes has been changed to Acme + DemoBundle directory. You can find them in + ```Acme\DemoBundle\Resources\config\routing.yml``` + +Command +---------------- + * A new demo command has been added to the AcmeDemoBundle that will help you + remove the bundle once you want to start working on a clean copy of + Symfony2 Standard. You can call it like this: + ```app/console demo:self-remove``` and type ```y``` when prompted to remove + the bundle in order to confirm the action. Else the command will display a + list of actions that it will do when running in ```live``` mode. + Make sure that the user executing the command has the needed privilages to + delete the files and directories mentioned while in dry-run mode. + diff --git a/app/config/routing_dev.yml b/app/config/routing_dev.yml index 22a48ae8e1..48d27e0747 100644 --- a/app/config/routing_dev.yml +++ b/app/config/routing_dev.yml @@ -1,15 +1,6 @@ -_welcome: - pattern: / - defaults: { _controller: AcmeDemoBundle:Welcome:index } - -_demo_secured: - resource: "@AcmeDemoBundle/Controller/SecuredController.php" - type: annotation - -_demo: - resource: "@AcmeDemoBundle/Controller/DemoController.php" - type: annotation - prefix: /demo +_acme_demo: + resource: "@AcmeDemoBundle/Resources/config/routing.yml" + prefix: / _wdt: resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml" diff --git a/src/Acme/DemoBundle/Command/SelfRemoveCommand.php b/src/Acme/DemoBundle/Command/SelfRemoveCommand.php new file mode 100644 index 0000000000..ba19b6bd78 --- /dev/null +++ b/src/Acme/DemoBundle/Command/SelfRemoveCommand.php @@ -0,0 +1,143 @@ +setName('demo:self-remove') + ->setDescription('Remove the Acme vendor and DemoBundle from default Symfony Standard distribution') + ->setHelp( + <<%command.name% removes the AcmeBundle shipped with Symfony2 Standard. + +Since this operation is not reversible you will be asked if you are sure that +you want to delete the bundle. + +If you choose N then the system will run this in dry-run mode. +If you choose a then the system will abort this command. +If you choose y then the system will proceed and remove the AcmeDemoBundle +EOF + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + // Check if we have the confirmation from the user in order to actually delete this + $dialog = $this->getHelperSet()->get('dialog'); + + $routeRemovalWarning = 'Confirm removal of AcmeDemoBundle? [ayN] '; + $confirm = $dialog->ask($output, $routeRemovalWarning, 'n'); + + switch (strtolower($confirm)) { + case 'a': + $output->writeln("Aborting operation"); + + return; + case 'y': + $confirm = true; + break; + default: + $confirm = false; + } + + // Get the path to our Vendor/Bundle directory + $path = realpath(__DIR__ . '/../../'); + + if ($confirm) { + $message = 'Removing: '; + } else { + $message = 'Dry-run: '; + } + + $output->writeln(sprintf("%s Removing AcmeDemoBundle directory (%s)", $message, $path)); + + if ($confirm) { + $fs = new Filesystem(); + + try { + $fs->remove($path); + } catch (IOException $e) { + $output->writeln("An error occured while removing the AcmeDemoBundle directory"); + } + } + + // Next step is to remove the routes to the bundle + + // Get the Kernel dir path + $kernelDirPath = $this->getContainer()->get('kernel')->getRootDir(); + + // Change the routes file + $routesFile = $kernelDirPath . '/config/routing_dev.yml'; + $output->writeln('Changing the contents of the routes file ... ' . $routesFile); + + // Remove just the routes that are related to Acme/DemoBundle + if ($confirm) { + $routesContents = file($routesFile); + $routesCount = count($routesContents); + + $foundMatch = false; + $i = 0; + while ($i < $routesCount) { + if ($routesContents[$i] == "_acme_demo:\n") { + $foundMatch = true; + unset($routesContents[$i]); + $i++; + continue; + } + + if ($foundMatch) { + if (strpos($routesContents[$i], "\t") !== false || + strpos($routesContents[$i], " ") !== false + ) { + unset($routesContents[$i]); + } else { + break; + } + } + + $i++; + } + + // Restore the file contents + $routesContents = implode('', $routesContents); + file_put_contents($routesFile, $routesContents); + } + + // The final step is to change the AppKernel Contents + + // Get the kernel file + $kernelFile = $kernelDirPath . '/AppKernel.php'; + $output->writeln('Changing the contents of AppKernel ... ' . $kernelFile); + + // Get the contents + $kernelContents = file_get_contents($kernelFile); + + // Remove the AcmeDemoBundle + $kernelContents = preg_replace( + '/\s+\\$bundles\[\]\s+=\s+new Acme\\\\DemoBundle\\\\AcmeDemoBundle\(\);/m', + '', + $kernelContents + ); + + // Check if we can save the new kernel file + if ($confirm) { + file_put_contents($kernelFile, $kernelContents); + } + + $output->writeln(''); + + // Finish + $output->writeln('Done'); + } +} diff --git a/src/Acme/DemoBundle/Resources/config/routing.yml b/src/Acme/DemoBundle/Resources/config/routing.yml new file mode 100644 index 0000000000..f95dc84b90 --- /dev/null +++ b/src/Acme/DemoBundle/Resources/config/routing.yml @@ -0,0 +1,12 @@ +_welcome: + pattern: / + defaults: { _controller: AcmeDemoBundle:Welcome:index } + +_demo_secured: + resource: "@AcmeDemoBundle/Controller/SecuredController.php" + type: annotation + +_demo: + resource: "@AcmeDemoBundle/Controller/DemoController.php" + type: annotation + prefix: /demo