1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alcalyn\PayplugBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
6
|
|
|
use Symfony\Component\Config\FileLocator; |
7
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
8
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* This is the class that loads and manages your bundle configuration |
12
|
|
|
* |
13
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
14
|
|
|
*/ |
15
|
|
|
class AlcalynPayplugExtension extends Extension |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* {@inheritDoc} |
19
|
|
|
*/ |
20
|
|
|
public function load(array $configs, ContainerBuilder $container) |
21
|
|
|
{ |
22
|
|
|
$configuration = new Configuration(); |
23
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
24
|
|
|
|
25
|
|
|
// Payplug account parameters |
26
|
|
|
foreach ($config['account'] as $key => $value) { |
27
|
|
|
$container->setParameter('payplug.account.'.$key, $value); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
// Sandbox parameters |
31
|
|
|
$this->loadSandboxParameters($config, $container); |
32
|
|
|
|
33
|
|
|
// Entities classes to use |
34
|
|
|
foreach ($config['class'] as $key => $value) { |
35
|
|
|
$container->setParameter('payplug.class.'.$key, $value); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
39
|
|
|
$loader->load('services.yml'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Load sandbox parameters, or set null if not |
44
|
|
|
* |
45
|
|
|
* @param array $config |
46
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
47
|
|
|
*/ |
48
|
|
|
private function loadSandboxParameters(array $config, ContainerBuilder $container) |
49
|
|
|
{ |
50
|
|
|
$paramPrefix = 'payplug.sandbox.account.'; |
51
|
|
|
|
52
|
|
|
$container->setParameter('payplug.sandbox.enabled', false); |
53
|
|
|
$container->setParameter($paramPrefix.'url', null); |
54
|
|
|
$container->setParameter($paramPrefix.'yourPrivateKey', null); |
55
|
|
|
|
56
|
|
|
if (isset($config['sandbox']['enabled'])) { |
57
|
|
|
$container->setParameter('payplug.sandbox.enabled', $config['sandbox']['enabled']); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if (isset($config['sandbox']['account'])) { |
61
|
|
|
$sandbox = $config['sandbox']['account']; |
62
|
|
|
|
63
|
|
|
if (isset($sandbox['url'])) { |
64
|
|
|
$container->setParameter($paramPrefix.'url', $sandbox['url']); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if (isset($sandbox['yourPrivateKey'])) { |
68
|
|
|
$container->setParameter($paramPrefix.'yourPrivateKey', $sandbox['yourPrivateKey']); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|