1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nexy\PayboxDirect\Bundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Nexy\PayboxDirect\Paybox; |
6
|
|
|
use Symfony\Component\Config\FileLocator; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
9
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Sullivan Senechal <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
final class NexyPayboxDirectExtension extends Extension |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* {@inheritdoc} |
18
|
|
|
*/ |
19
|
|
|
public function load(array $configs, ContainerBuilder $container) |
20
|
|
|
{ |
21
|
|
|
$configuration = new Configuration(); |
22
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
23
|
|
|
|
24
|
|
|
$this->processOptions($config, $container); |
25
|
|
|
|
26
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
27
|
|
|
$loader->load('sdk.xml'); |
28
|
|
|
$loader->load('http_clients.xml'); |
29
|
|
|
|
30
|
|
|
$this->processClient($config, $container); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param array $config |
35
|
|
|
* @param ContainerBuilder $container |
36
|
|
|
*/ |
37
|
|
|
private function processOptions(array $config, ContainerBuilder $container) |
38
|
|
|
{ |
39
|
|
|
// Start with client option |
40
|
|
|
$options = $config['options']; |
41
|
|
|
|
42
|
|
|
// Paybox version and devise special hack: Get the number. |
43
|
|
|
$options['paybox_version'] = Paybox::VERSIONS[$config['paybox']['version']]; |
44
|
|
|
unset($config['paybox']['version']); |
45
|
|
|
if (array_key_exists('devise', $config['paybox'])) { |
46
|
|
|
$options['paybox_devise'] = Paybox::DEVISES[$config['paybox']['devise']]; |
47
|
|
|
unset($config['paybox']['devise']); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// Convert paybox option format |
51
|
|
|
foreach ($config['paybox'] as $key => $value) { |
52
|
|
|
$options['paybox_'.$key] = $value; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$container->setParameter('nexy_paybox_direct.options', $options); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param array $config |
60
|
|
|
* @param ContainerBuilder $container |
61
|
|
|
*/ |
62
|
|
|
private function processClient(array $config, ContainerBuilder $container) |
63
|
|
|
{ |
64
|
|
|
if (null === $config['client']) { |
65
|
|
|
return; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$container->findDefinition('nexy_paybox_direct.sdk')->addArgument( |
69
|
|
|
$container->findDefinition('nexy_paybox_direct.http_client.'.$config['client']) |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|