Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename a bundle in symfony?

My bundle is located at src/Cinergy/Bundle/ComponentBundle/CinergyComponentBundle.php and the logical name of the bundle is 'CinergyComponentBundle'.

Since I did not stick to the naming convention of the company I have to change the logcial name of the bundle. Lets asume I have to rename it to 'XXXCinergyComponentBundle'

What files do I need to change?

I tried renaming the CinergyComponentBundle.php file and the containing class into XXXCinergyComponentBundle.php. I also changed the reference in AppKernel.

Unfortunately this does not work. When I try to clear the cache I get this error message:

[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]                                   
The service "cinergy.people.direct.php" has a dependency on a non-existent service "cinergy.work.registry". 

This two services do belong to the bundle with the new name. This leads me to the conclusion that I'm missing something in the renaming process.

Any ideas?

like image 880
BetaRide Avatar asked Sep 21 '12 08:09

BetaRide


3 Answers

I have just completed renaming a bundle myself and ended up at the exact same point as you did a couple of minutes ago. To this point I have used my editors replace-function. It turns out there are some files that need some extra care, which are located here (assuming your old Bundle name was AcmeOldBundle, new will be AcmeNewBundle):

  1. Acme\OldBundle\OldBundle.php -> NewBundle.php
  2. Acme\OldBundle\DependencyInjection\AcmeOldExtension.php -> AcmeNewExtension.php

Do not forget to update the class-names inside the files as well.

like image 60
zebba Avatar answered Nov 10 '22 05:11

zebba


The current answers do indeed explain what to do to rename a bundle but they leave out a few things:

  1. Rename the bundle in /app/AppKernel.php

    From:

    $bundles = [
        // ...
        new Acme\OldBundle\AcmeOldBundle(),
    ];
    

    To:

    $bundles = [
        // ...
        new Acme\NewBundle\AcmeNewBundle(),
    ];
    
  2. Renaming files and folders

    You need to rename the files and folders containing your code:

    src/Acme/OldBundle -> src/Acme/NewBundle
    src/Acme/OldBundle/OldBundle.php -> src/Acme/NewBundle/NewBundle.php
    
    # If present
    src/Acme/OldBundle/DependencyInjection/AcmeOldExtension.php -> src/Acme/NewBundle/DependencyInjection/AcmeNewExtension.php
    
  3. Namespaces

    This will probably go with forgetting a few files and searching around your bundle for each and every match. The best thing to do is doing a find-replace:

    # find -> replace
    acme_old -> acme_new
    Acme\OldBundle\ -> Acme\NewBundle
    AcmeOld -> AcmeNew
    Acme:Old -> Acme:New
    Acme:OldBundle -> Acme:NewBundle
    

    Be sure to check all namespaces, class names and configuration files in your bundle.

  4. Global configuration files

    Search for any occurrence of your old bundle name in app/config/ and replace it with your new bundle name.

like image 21
Peter Avatar answered Nov 10 '22 05:11

Peter


You need to update the entire namespace in each files.

You were using namespace Cynergy\ComponentBundle\Something; but you're now using namespace XXXCynergy\ComponentBundle\Something;

Don't forget to update your services.(xml|yml).

like image 3
Boris Guéry Avatar answered Nov 10 '22 05:11

Boris Guéry