Search code examples
business-logicsymfony

Dependencies Symfony2


I'm wondering if there is a proper way to check the dependencies.

For example I've got a NewsBundle. Now I'll have to check if there is a CommentBundle. If there is one, it should execute a few more Code.

Any suggestions?


Solution

  • 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.