Generates and caches a standalone Symfony DI container.
Create a new Configuration object
$generatorConfiguration = ContainerTools\Configuration::fromParameters(
'/var/cache/container.php', // name of file for compiled container
['/etc/services/', '/project/services'], // where to expect services.xml and services_test.xml
true|false, // debug mode - doesn't cache or generate container.php if true
'xml'|'yml' // services extension 'xml' or 'yml'
);
Instantiate a ContainerGenerator, and fetch the container from it:
$generator = new \ContainerTools\ContainerGenerator($generatorConfiguration);
$container = $generator->getContainer();
$mailer = $container->get('acme.mailer');
ContainerGenerator expects at least one services.xml file to exist, and will throw an exception if none are found.
Sometimes its neccessary, in a test environment, to provide mock services that replace the real services, these can be provided in services_test.xml and use the configuration switch:
$generatorConfiguration->setTestEnvironment(true);
If any service_test.xml files exist they will be loaded subsequently. Symfonys' configuration loader will merge the configurations and override test service definitions with production ones. (similarly for services.yml if 'yml' is configured)