Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8743729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:43:42+00:00 2026-06-13T11:43:42+00:00

Maybe something similar to the generate:bundle command (which after generating the bundle prompts to

  • 0

Maybe something similar to the generate:bundle command (which after generating the bundle prompts to update the AppKernel) or to Composer (which updates your autoload with the dependencies you install).

I want to get a similar functionality to the generate:bundle, but instead of creating a new bundle I want to add a bundle I just downloaded without having to edit the AppKernel manually.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:43:43+00:00Added an answer on June 13, 2026 at 11:43 am

    I couldn’t find a way to EXTEND an existing command, so my thought goes to create a new console command into an existing bundle.

    namespace Your\OriginalBundle\Command;
    
    use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
    use Symfony\Component\Console\Input\ArrayInput;
    use Symfony\Component\Console\Input\InputArgument;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Input\InputOption;
    use Symfony\Component\Console\Output\OutputInterface;
    
    class AppendNewBundleCommand extends ContainerAwareCommand
    {
        protected $appKernel;
    
        protected function configure()
        {
            $this
                ->setName('yourbundle:appendnewbundle')
                ->setDescription('Append a new bundle to the AppKernel.php')
                ->addArgument('namespace', InputArgument::REQUIRED, 'Define your new bundle/namespace')
            ;
            $this->appKernel = __DIR__.'/../../../../app/AppKernel.php';
        }
    
        protected function execute(InputInterface $input, OutputInterface $output)
        {
            if (!file_exists($this->appKernel)) {
                throw new \ErrorException(sprintf("Could not locate file %s",$this->appKernel));
            }
            if (!is_writable($this->appKernel)) {
                throw new \ErrorException(sprintf('Cannot write into AppKernel (%s)',$this->appKernel));
            }
    
            $namespace = $input->getArgument('namespace');
            $appContent = file_get_contents($this->appKernel);
    
            $bundle = str_replace("/","\\",$namespace)."\\".str_replace("/","",$namespace);
            $newBundle = "new {$bundle}(),";
    
            $pattern = '/\$bundles\s?=\s?array\((.*?)\);/is';
            preg_match($pattern, $appContent,$matches);
    
            $bList = rtrim($matches[1],"\n ");
            $e = explode(",",$bList);
            $firstBundle = array_shift($e);
            $tabs = substr_count($firstBundle,'    ');
    
            $newBList = "\$bundles = array("
                                .$bList."\n"
                                .str_repeat('    ', $tabs).$newBundle."\n"
                            .str_repeat('    ',$tabs-1).");";
    
            file_put_contents($this->appKernel,preg_replace($pattern,$newBList,$appContent));
        }
    }
    

    You can now execute it, right after generating your bundle by doing

    php app/console yourbundle:appendnewbundle Your/SecondBundle
    

    This will append this to the list of existing bundles

    new Your\SecondBundle\YourSecondBundle(),
    

    This works if you have a standard (symfony2) AppKernel. Ex:

    <?php
    
    use Symfony\Component\HttpKernel\Kernel;
    use Symfony\Component\Config\Loader\LoaderInterface;
    
    class AppKernel extends Kernel
    {
        public function registerBundles()
        {
            $bundles = array(
                new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
                new Symfony\Bundle\SecurityBundle\SecurityBundle(),
                new Symfony\Bundle\TwigBundle\TwigBundle(),
                new Symfony\Bundle\MonologBundle\MonologBundle(),
                new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
                new Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
                new Symfony\Bundle\AsseticBundle\AsseticBundle(),
                new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
                new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
                new Ornicar\ApcBundle\OrnicarApcBundle(),
                new Your\OriginalBundle\YourOriginalBundle(),
            );
    
            if (in_array($this->getEnvironment(), array('dev', 'test'))) {
                $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
                $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
                $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
            }
    
            return $bundles;
        }
    
        public function registerContainerConfiguration(LoaderInterface $loader)
        {
            $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: After some additional reading, what I really wanted was guaranteed early binding (which
This problem is caused by my acknowledge of English and jQuery or maybe something
I am having a strange problem, maybe something to do with Apache more than
is there a way to 'break' out of a groovy closure. maybe something like
Is there any Fluent WCF interface out there worth using? Maybe something like these:
Hi if someone could look at my code and maybe see something I am
Maybe im missing something but im not sure. All im simply trying to do
Maybe this is something very easy to do it but so far it's taking
Maybe I missed something, but I cant figure out why Visual Studio 2008 isn't
I was reading Simply Rails by Patrick Lenz... maybe I missed something, it seems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.