php - Symfony 2.3 - Disable bundles based on service data


I would like to disable some bundles based on the data stored in database. I know I can do that based on the environment:


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\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle()             );

        // Environment based bundles
        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)

However that doesn't obviously answer this question, can I inject services intoAppKernel itself? Or can I inject them into bundle itself and somehow disable it?




If I was you, I would do the following

  1. Create a simple bundle, which would handle the request to the database and all such stuff
  2. Register this bundle in
  3. CreateYourKernel class and extend it from
  4. "Inject"YourKernel it into
  5. InYourKernel redefine method, in which you would get the list of bundle and boot needed ones, dependent on the returned value.

People are also looking for solutions to the problem: php - Selectively post form to different pages, based on form result?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.