-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathMatthiasDependencyInjectionTestExtension.php
More file actions
78 lines (64 loc) · 2.76 KB
/
MatthiasDependencyInjectionTestExtension.php
File metadata and controls
78 lines (64 loc) · 2.76 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?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\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\ContainerBuilderHasFactoryConstraint;
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');
// load factory services definitions
if (ContainerBuilderHasFactoryConstraint::isLegacySymfonyDI()) {
$loader->load('services-factory-legacy.xml');
} else {
$loader->load('services-factory.xml');
// Load old syntax for services in YML files
$ymlLoader = new YamlFileLoader($container, new FileLocator(__DIR__));
$ymlLoader->load('services-factory-old-syntax.yml');
}
// 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', 'stdClass');
if (ContainerBuilderHasFactoryConstraint::isLegacySymfonyDI()) {
$container
->register('manual_created_by_factory_service', 'stdClass')
->setFactoryService(new Reference('manual_factory_service'))
->setFactoryMethod('factoryMethod');
;
} else {
$container
->register('manual_created_by_factory_service', 'stdClass')
->setFactory('manual_factory_service:factoryMethod')
;
}
}
public function getAlias()
{
return 'matthias_dependency_injection_test';
}
public function getNamespace()
{
}
public function getXsdValidationBasePath()
{
}
}