|
| 1 | +.. index:: |
| 2 | + single: Bundle; Removing AcmeDemoBundle |
| 3 | + |
| 4 | +How to remove the AcmeDemoBundle |
| 5 | +================================ |
| 6 | + |
| 7 | +The Symfony2 Standard Edition comes with a complete demo, that lives inside a |
| 8 | +bundle called ``AcmeDemoBundle``. It is a great boilerplate to refer to while |
| 9 | +starting with your project, but later on the project, it will become usefull |
| 10 | +to remove this bundle. |
| 11 | + |
| 12 | +.. tip:: |
| 13 | + |
| 14 | + This article uses the AcmeDemoBundle as an example, you can use this |
| 15 | + article on every bundle you want to remove. |
| 16 | + |
| 17 | +1. Unregister the bundle in the ``AppKernel`` |
| 18 | +--------------------------------------------- |
| 19 | + |
| 20 | +To disconnect the bundle from the framework, you should remove the bundle from |
| 21 | +the ``Appkernel::registerBundles()`` method. The bundle is normally found in |
| 22 | +the ``$bundles`` array but the ``AcmeDemoBundle`` is only registered in a |
| 23 | +development environment and you can find him in the if statement thereafter:: |
| 24 | + |
| 25 | + // app/AppKernel.php |
| 26 | + |
| 27 | + // ... |
| 28 | + class AppKernel extends Kernel |
| 29 | + { |
| 30 | + public function registerBundles() |
| 31 | + { |
| 32 | + $bundles = array(...); |
| 33 | + |
| 34 | + if (in_array($this->getEnvironment(), array('dev', 'test'))) { |
| 35 | + // comment or remove this line: |
| 36 | + // $bundles[] = new Acme\DemoBundle\AcmeDemoBundle(); |
| 37 | + // ... |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | +2. Remove bundle configuration |
| 43 | +------------------------------ |
| 44 | + |
| 45 | +Now Symfony doesn't know about the bundle, you need to remove any |
| 46 | +configuration and routing configuration inside the ``app/config`` directory |
| 47 | +that refers to the bundle. |
| 48 | + |
| 49 | +2.1 Remove bundle routing |
| 50 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 51 | + |
| 52 | +The routing for the AcmeDemoBundle can be found in |
| 53 | +``app/config/routing_dev.yml``. The routes are ``_welcome``, ``_demo_secured`` |
| 54 | +and ``_demo``. |
| 55 | + |
| 56 | +2.2 Remove bundle configuration |
| 57 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 58 | + |
| 59 | +Some bundles contains configuration in one of the ``app/config/config*.yml`` |
| 60 | +files. Be sure to remove the related configuration from these files. You can |
| 61 | +quickly spot bundle configuration by looking at a ``acme_demo`` (or whatever |
| 62 | +the name of the bundle is, e.g. ``fos_user`` with the FOSUserBundle) string in |
| 63 | +the configuration files. |
| 64 | + |
| 65 | +The AcmeDemoBundle doesn't have configuration. However, the bundle has set up |
| 66 | +the ``app/config/security.yml`` file. You can use it as a boilerplate for your |
| 67 | +own security, but you **can** also remove everything: It doesn't make sense to |
| 68 | +Symfony if you remove it or not. |
| 69 | + |
| 70 | +3. Remove integration in other bundles |
| 71 | +-------------------------------------- |
| 72 | + |
| 73 | +Some bundles rely on other bundles, if you remove one of the two, the other |
| 74 | +will properbly not work. Be sure that no other bundles, third party or self |
| 75 | +made, relies on the bundle you are about to remove. |
| 76 | + |
| 77 | +.. tip:: |
| 78 | + |
| 79 | + If a bundle relies on another bundle, it means in most of the cases that |
| 80 | + it uses some services from the other bundle. Searching for a ``acme_demo`` |
| 81 | + string will help you spot them. |
| 82 | + |
| 83 | +.. tip:: |
| 84 | + |
| 85 | + If a third party bundle relies on another bundle, you can find the bundle |
| 86 | + in the ``composer.json`` file included in the bundle directory. |
| 87 | + |
| 88 | +4. Remove the bundle from the filesystem |
| 89 | +---------------------------------------- |
| 90 | + |
| 91 | +Now you have removed every reference to the bundle in the Symfony2 |
| 92 | +application, the last thing you should do is removing the bundle from the file |
| 93 | +system. The bundle is located in the ``src/Acme/DemoBundle`` directory. You |
| 94 | +should remove this directory and you can remove the ``Acme`` directory as |
| 95 | +well, you likely won't get other bundles in that vendor. |
| 96 | + |
| 97 | +.. tip:: |
| 98 | + |
| 99 | + If you don't know the location of a bundle, you can use the |
| 100 | + :method:`Symfony\\Bundle\\FrameworkBundle\\Bundle\\Bundle::getPath` method |
| 101 | + to get the path of the bundle:: |
| 102 | + |
| 103 | + echo $this->container->get('kernel')->getBundle('AcmeDemoBundle')->getPath(); |
0 commit comments