This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container9.php
Fabien Potencier efed6005cb [DependencyInjection] fixed PHP dumper
In the dumped PHP class, we must use get() and not get*Service() methods to get services.
That's because all calls must be managed by get(). From the outside, you can call
get*Service() because as they are protected, they are caught by the __call() method;
which is not the case obviously when it is used internally.

If not, if you override a service with set(), this won't work when a service
depends on this one (the default one will still be used).
2010-11-12 17:38:32 +01:00

56 lines
2.0 KiB
PHP

<?php
require_once __DIR__.'/../includes/classes.php';
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
$container = new ContainerBuilder();
$container->
register('foo', 'FooClass')->
addTag('foo', array('foo' => 'foo'))->
addTag('foo', array('bar' => 'bar'))->
setFactoryMethod('getInstance')->
setArguments(array('foo', new Reference('foo.baz'), array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, new Reference('service_container')))->
setShared(false)->
addMethodCall('setBar', array(new Reference('bar')))->
addMethodCall('initialize')->
setConfigurator('sc_configure')
;
$container->
register('bar', 'FooClass')->
setArguments(array('foo', new Reference('foo.baz'), new Parameter('foo_bar')))->
setShared(true)->
setConfigurator(array(new Reference('foo.baz'), 'configure'))
;
$container->
register('foo.baz', '%baz_class%')->
setFactoryMethod('getInstance')->
setConfigurator(array('%baz_class%', 'configureStatic1'))
;
$container->register('foo_bar', '%foo_class%');
$container->getParameterBag()->clear();
$container->getParameterBag()->add(array(
'baz_class' => 'BazClass',
'foo_class' => 'FooClass',
'foo' => 'bar',
));
$container->setAlias('alias_for_foo', 'foo');
$container->
register('method_call1', 'FooClass')->
setFile(realpath(__DIR__.'/../includes/foo.php'))->
addMethodCall('setBar', array(new Reference('foo')))->
addMethodCall('setBar', array(new Reference('foo', ContainerInterface::NULL_ON_INVALID_REFERENCE)))->
addMethodCall('setBar', array(new Reference('foo', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))->
addMethodCall('setBar', array(new Reference('foobaz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))
;
$container->
register('factory_service')->
setFactoryService('foo.baz')->
setFactoryMethod('getInstance')
;
return $container;