Tobias Hagenbeek
Tobias Hagenbeek

Reputation: 1213

Use container:debug results in Symfony controller

When you run app/console container:debug you get a list of all defined services. I would like to use this list (definitions only) in my controller (extending Symfony controller), i want to use that list to run through and see if i can recognize a service.

Another option would be star loading services as in $this->get('example.start*') or something in that fassion, anyone ever done this? Did i miss some documentation?

Thanks!! Have a good one everybody!

Upvotes: 0

Views: 263

Answers (1)

SilvioQ
SilvioQ

Reputation: 2072

I hope it's useful for you ...

Check http://api.symfony.com/2.5/Symfony/Component/DependencyInjection/ContainerBuilder.html more data ...

use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;                      

class   SomeController
{
    public  function   containerDebuglAction()
    {
        print_r( array_keys( $this->getContainerBuilder()->getDefinitions() ) );
    }


    /** 
     * Loads the ContainerBuilder from the cache.                                                                                               
     *      
     * @return ContainerBuilder                                                                                                                 
     *                                                                                                                                          
     * @throws \LogicException
     */ 
    protected function getContainerBuilder()
    {   
        if (!is_file($cachedFile = $this->get('service_container')->getParameter('debug.container.dump'))) {                                    
            throw new \LogicException(sprintf('Debug information about the container could not be found. Please clear the cache and try again.')
        }                                                                                                                                       

        $container = new ContainerBuilder();                                                                                                    

        $loader = new XmlFileLoader($container, new FileLocator());                                                                             
        $loader->load($cachedFile);

        return $container;                                                                                                                      
    }       
}

Upvotes: 1

Related Questions