|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gewebe\SyliusVATPlugin\DependencyInjection; |
|
6
|
|
|
|
|
7
|
|
|
use Sylius\Bundle\CoreBundle\DependencyInjection\PrependDoctrineMigrationsTrait; |
|
8
|
|
|
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension; |
|
9
|
|
|
use Symfony\Component\Config\FileLocator; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
13
|
|
|
|
|
14
|
|
|
final class GewebeSyliusVATExtension extends AbstractResourceExtension implements PrependExtensionInterface |
|
15
|
|
|
{ |
|
16
|
|
|
use PrependDoctrineMigrationsTrait; |
|
17
|
|
|
|
|
18
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
|
19
|
|
|
{ |
|
20
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../config')); |
|
21
|
|
|
$loader->load('services.yaml'); |
|
22
|
|
|
|
|
23
|
|
|
$configuration = $this->getConfiguration([], $container); |
|
24
|
|
|
if ($configuration === null) { |
|
25
|
|
|
return; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** @var string[][] $configs */ |
|
29
|
|
|
$configs = $this->processConfiguration($configuration, $configs); |
|
30
|
|
|
|
|
31
|
|
|
$definition = $container->getDefinition('gewebe_sylius_vat_plugin.order_processor'); |
|
32
|
|
|
$definition->replaceArgument(3, $configs['order']['recalculate']); |
|
33
|
|
|
|
|
34
|
|
|
$definition = $container->getDefinition('gewebe_sylius_vat_plugin.validator'); |
|
35
|
|
|
$definition->replaceArgument(1, $configs['validate']['is_active']); |
|
36
|
|
|
$definition->replaceArgument(2, $configs['validate']['country']); |
|
37
|
|
|
$definition->replaceArgument(3, $configs['validate']['existence']); |
|
38
|
|
|
$definition->replaceArgument(4, $configs['required']['company']); |
|
39
|
|
|
$definition->replaceArgument(5, $configs['required']['countries']); |
|
40
|
|
|
|
|
41
|
|
|
$definition = $container->getDefinition('gewebe_sylius_vat_plugin.form.extension.address'); |
|
42
|
|
|
$definition->replaceArgument(0, $configs['required']['default']); |
|
43
|
|
|
|
|
44
|
|
|
$definition = $container->getDefinition('Gewebe\SyliusVATPlugin\EventListener\LoginListener'); |
|
45
|
|
|
$definition->replaceArgument(1, $configs['revalidate']['on_login']); |
|
46
|
|
|
$definition->replaceArgument(2, $configs['revalidate']['expiration_days']); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function prepend(ContainerBuilder $container): void |
|
50
|
|
|
{ |
|
51
|
|
|
$this->prependDoctrineMigrations($container); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
protected function getMigrationsNamespace(): string |
|
55
|
|
|
{ |
|
56
|
|
|
return 'Gewebe\SyliusVATPlugin\Migrations'; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
protected function getMigrationsDirectory(): string |
|
60
|
|
|
{ |
|
61
|
|
|
return '@GewebeSyliusVATPlugin/src/Migrations'; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
protected function getNamespacesOfMigrationsExecutedBefore(): array |
|
65
|
|
|
{ |
|
66
|
|
|
return [ |
|
67
|
|
|
'Sylius\Bundle\CoreBundle\Migrations', |
|
68
|
|
|
]; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|