|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zenstruck\Foundry\Bundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
8
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; |
|
9
|
|
|
use Zenstruck\Foundry\Story; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @author Kevin Bond <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
final class ZenstruckFoundryExtension extends ConfigurableExtension |
|
15
|
|
|
{ |
|
16
|
20 |
|
protected function loadInternal(array $mergedConfig, ContainerBuilder $container): void |
|
17
|
|
|
{ |
|
18
|
20 |
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
19
|
|
|
|
|
20
|
20 |
|
$loader->load('services.xml'); |
|
21
|
|
|
|
|
22
|
20 |
|
$container->registerForAutoconfiguration(Story::class) |
|
23
|
20 |
|
->addTag('foundry.story') |
|
24
|
|
|
; |
|
25
|
|
|
|
|
26
|
20 |
|
$this->configureFaker($mergedConfig['faker'], $container); |
|
27
|
20 |
|
$this->configureDefaultInstantiator($mergedConfig['instantiator'], $container); |
|
28
|
20 |
|
} |
|
29
|
|
|
|
|
30
|
20 |
|
private function configureFaker(array $config, ContainerBuilder $container): void |
|
31
|
|
|
{ |
|
32
|
20 |
|
if ($config['service']) { |
|
33
|
4 |
|
$container->setAlias('zenstruck_foundry.faker', $config['service']); |
|
34
|
|
|
|
|
35
|
4 |
|
return; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
16 |
|
if ($config['locale']) { |
|
39
|
4 |
|
$container->getDefinition('zenstruck_foundry.faker')->addArgument($config['locale']); |
|
40
|
|
|
} |
|
41
|
16 |
|
} |
|
42
|
|
|
|
|
43
|
20 |
|
private function configureDefaultInstantiator(array $config, ContainerBuilder $container): void |
|
44
|
|
|
{ |
|
45
|
20 |
|
if ($config['service']) { |
|
46
|
4 |
|
$container->setAlias('zenstruck_foundry.default_instantiator', $config['service']); |
|
47
|
|
|
|
|
48
|
4 |
|
return; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
16 |
|
$definition = $container->getDefinition('zenstruck_foundry.default_instantiator'); |
|
52
|
|
|
|
|
53
|
16 |
|
if ($config['without_constructor']) { |
|
54
|
4 |
|
$definition->addMethodCall('withoutConstructor'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
16 |
|
if ($config['allow_extra_attributes']) { |
|
58
|
4 |
|
$definition->addMethodCall('allowExtraAttributes'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
16 |
|
if ($config['always_force_properties']) { |
|
62
|
4 |
|
$definition->addMethodCall('alwaysForceProperties'); |
|
63
|
|
|
} |
|
64
|
16 |
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|