Dependencies Symfony2 Dependencies Symfony2 symfony symfony

Dependencies Symfony2


In addition to markymark's answer, you can check if a specific service exists from your controller (or any other container-aware code) with the following snippet:

if ($this->container->has('foo_service.alias')){    // service is loaded and usable}

If you're not sure of the exact alias of a given service, or just for kicks and giggles, you can run the console command php app/console container:debug to see all services registered with the container.


You could use class_exists on the main Bundle class that every bundle should have.

For example:

if (class_exists('Acme\CommentBundle\AcmeCommentBundle')){    // Bundle exists and is loaded by AppKernel...}


The Kernel class contains a list of helper methods to check if a certain class is part of an active bundle or if a bundle is registered.

public BundleInterface[] getBundles()    Gets the registered bundle instances.public bool isClassInActiveBundle(string $class)    Checks if a given class name belongs to an active bundle.