-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathMatthiasDependencyInjectionTestExtension.php
More file actions
58 lines (46 loc) · 1.86 KB
/
MatthiasDependencyInjectionTestExtension.php
File metadata and controls
58 lines (46 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\FileLocator;
class MatthiasDependencyInjectionTestExtension implements ExtensionInterface
{
public function load(array $config, ContainerBuilder $container)
{
// load some service definitions
$loader = new XmlFileLoader($container, new FileLocator(__DIR__));
$loader->load('services.xml');
// set a parameter manually
$container->setParameter('manual_parameter', 'parameter value');
// manually add a service definition
$definition = new Definition('stdClass');
$definition->setArguments(array('first', 'second'));
$container->setDefinition('manual_service_id', $definition);
// replace an argument of a previously defined service definition
$container
->getDefinition('manual_service_id')
->replaceArgument(1, 'argument value');
// add an alias to an existing service
$container->setAlias('manual_alias', 'service_id');
// add an factory service
$container
->register( 'manual_factory_service', new Definition() );
$container
->register( 'manual_created_by_factory_service', new Definition() )
->setFactory( [new Reference('manual_factory_service'), 'factoryMethod'] )
;
}
public function getAlias()
{
return 'matthias_dependency_injection_test';
}
public function getNamespace()
{
}
public function getXsdValidationBasePath()
{
}
}