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\Loader\YamlFileLoader; |
9
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
10
|
|
|
|
11
|
|
|
class LoevgaardDandomainAltapayExtension extends Extension |
12
|
|
|
{ |
13
|
|
|
public function load(array $configs, ContainerBuilder $container) |
14
|
|
|
{ |
15
|
|
|
$configuration = new Configuration(); |
16
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
17
|
|
|
|
18
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.altapay_username', $config['altapay_username']); |
19
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.altapay_password', $config['altapay_password']); |
20
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.altapay_ips', $config['altapay_ips']); |
21
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.altapay_url', $config['altapay_url']); |
22
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.shared_key_1', $config['shared_key_1']); |
23
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.shared_key_2', $config['shared_key_2']); |
24
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.cookie_payment_id', $config['cookie_payment_id']); |
25
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.cookie_checksum_complete', $config['cookie_checksum_complete']); |
26
|
|
|
|
27
|
|
|
// set default settings |
28
|
|
|
$container->setParameter('loevgaard_dandomain_altapay.default_settings.layout.logo', $config['default_settings']['layout']['logo']); |
29
|
|
|
|
30
|
|
|
$this->verifyDefaultSettings($container); |
31
|
|
|
|
32
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
33
|
|
|
$loader->load('services.yml'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* This method will verify that all available settings in the SiteSetting are defined as parameters |
38
|
|
|
* |
39
|
|
|
* @param ContainerBuilder $container |
40
|
|
|
* @throws \RuntimeException |
41
|
|
|
*/ |
42
|
|
|
private function verifyDefaultSettings(ContainerBuilder $container) |
43
|
|
|
{ |
44
|
|
|
$settings = SiteSetting::getSettings(); |
45
|
|
|
foreach ($settings as $setting) { |
46
|
|
|
$parameter = 'loevgaard_dandomain_altapay.default_settings.'.$setting; |
47
|
|
|
if(!$container->hasParameter($parameter)) { |
48
|
|
|
throw new \RuntimeException('The parameter `'.$parameter.'` is not configured in the code'); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|