1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainAltapayBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\SiteSetting; |
6
|
|
|
use Symfony\Component\Config\FileLocator; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
9
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
10
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
11
|
|
|
|
12
|
|
|
class LoevgaardDandomainAltapayExtension extends Extension implements PrependExtensionInterface |
13
|
|
|
{ |
14
|
|
|
public function load(array $configs, ContainerBuilder $container) |
15
|
|
|
{ |
16
|
|
|
$configuration = new Configuration(); |
17
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
18
|
|
|
|
19
|
|
|
$webhookUrls = $config['webhook_urls'] ?? []; |
20
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.altapay_username', $config['altapay_username']); |
21
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.altapay_password', $config['altapay_password']); |
22
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.altapay_ips', $config['altapay_ips']); |
23
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.altapay_url', $config['altapay_url']); |
24
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.shared_key_1', $config['shared_key_1']); |
25
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.shared_key_2', $config['shared_key_2']); |
26
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.cookie_payment_id', $config['cookie_payment_id']); |
27
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.cookie_checksum_complete', $config['cookie_checksum_complete']); |
28
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.webhook_urls', $webhookUrls); |
29
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.default_settings', $config['default_settings']); |
30
|
|
|
|
31
|
|
|
// set individual default settings |
32
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.default_settings.layout.logo', $config['default_settings']['layout']['logo']); |
33
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.default_settings.opening_days', $config['default_settings']['opening_days']); |
34
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.default_settings.opening_hours', $config['default_settings']['opening_hours']); |
35
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.default_settings.phone', $config['default_settings']['phone']); |
36
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.default_settings.email', $config['default_settings']['email']); |
37
|
|
|
|
38
|
|
|
$this->verifyDefaultSettings($container); |
39
|
|
|
|
40
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
41
|
|
|
$loader->load('services.yml'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* This method will verify that all available settings in the SiteSetting are defined as parameters. |
46
|
|
|
* |
47
|
|
|
* @param ContainerBuilder $container |
48
|
|
|
* |
49
|
|
|
* @throws \RuntimeException |
50
|
|
|
*/ |
51
|
|
|
private function verifyDefaultSettings(ContainerBuilder $container) |
52
|
|
|
{ |
53
|
|
|
$settings = SiteSetting::getSettings(); |
54
|
|
|
foreach ($settings as $setting) { |
55
|
|
|
$parameter = 'loevgaard_dandomain_altapay.default_settings.'.$setting; |
56
|
|
|
if (!$container->hasParameter($parameter)) { |
57
|
|
|
throw new \RuntimeException('The parameter `'.$parameter.'` is not configured in the code'); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function prepend(ContainerBuilder $container) |
63
|
|
|
{ |
64
|
|
|
foreach ($container->getExtensions() as $name => $extension) { |
65
|
|
|
if($name !== 'twig') { |
|
|
|
|
66
|
|
|
continue; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$container->prependExtensionConfig($name, [ |
70
|
|
|
'form_themes' => ['LexikFormFilterBundle:Form:form_div_layout.html.twig'] |
71
|
|
|
]); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|