|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Lexik\Bundle\PayboxBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
6
|
|
|
use Symfony\Component\Config\FileLocator; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
9
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* This is the class that loads and manages your bundle configuration |
|
14
|
|
|
* |
|
15
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
|
16
|
|
|
*/ |
|
17
|
|
|
class LexikPayboxExtension extends Extension |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* {@inheritDoc} |
|
21
|
|
|
*/ |
|
22
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
23
|
|
|
{ |
|
24
|
|
|
$configuration = new Configuration(); |
|
25
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
26
|
|
|
|
|
27
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
28
|
|
|
$loader->load('services.yml'); |
|
29
|
|
|
|
|
30
|
|
|
$this->processAccountsConfiguration($config, $container); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
private function processAccountsConfiguration(array $config, ContainerBuilder $container) |
|
34
|
|
|
{ |
|
35
|
|
|
foreach ($config['accounts'] as $name => $options) { |
|
36
|
|
|
if (null === $options['public_key']) { |
|
37
|
|
|
$options['public_key'] = __DIR__ . '/../Resources/config/paybox_public_key.pem'; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$options['parameters']['public_key'] = $options['public_key']; |
|
41
|
|
|
|
|
42
|
|
|
$this |
|
43
|
|
|
->createTransportService($name, $options, $container) |
|
44
|
|
|
->createRequestHandlerService($name, $options, $container) |
|
45
|
|
|
->createRequestCancellationHandlerService($name, $options, $container) |
|
46
|
|
|
->createResponseHandlerService($name, $options, $container) |
|
47
|
|
|
->createDirecPlusRequestHandlerService($name, $options, $container) |
|
48
|
|
|
; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
private function createTransportService($name, array $options, ContainerBuilder $container) |
|
53
|
|
|
{ |
|
54
|
|
|
$client = new Definition($options['transport']); |
|
55
|
|
|
|
|
56
|
|
|
$clientServiceId = sprintf('lexik_paybox.transport.%s', $name); |
|
57
|
|
|
$container->setDefinition($clientServiceId, $client); |
|
58
|
|
|
|
|
59
|
|
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
View Code Duplication |
private function createRequestHandlerService($name, array $options, ContainerBuilder $container) |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
$client = new Definition($container->getParameterBag()->get('lexik_paybox.request_handler.class')); |
|
65
|
|
|
|
|
66
|
|
|
$client->addArgument($name); |
|
67
|
|
|
$client->addArgument($options['parameters']); |
|
68
|
|
|
$client->addArgument($options['servers']); |
|
69
|
|
|
$client->addArgument(new Reference('form.factory')); |
|
70
|
|
|
|
|
71
|
|
|
$clientServiceId = sprintf('lexik_paybox.request_handler.%s', $name); |
|
72
|
|
|
$container->setDefinition($clientServiceId, $client); |
|
73
|
|
|
|
|
74
|
|
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
View Code Duplication |
private function createRequestCancellationHandlerService($name, array $options, ContainerBuilder $container) |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
$client = new Definition($container->getParameterBag()->get('lexik_paybox.request_cancellation_handler.class')); |
|
80
|
|
|
|
|
81
|
|
|
$client->addArgument($name); |
|
82
|
|
|
$client->addArgument($options['parameters']); |
|
83
|
|
|
$client->addArgument($options['servers']); |
|
84
|
|
|
$client->addArgument(new Reference(sprintf('lexik_paybox.transport.%s', $name))); |
|
85
|
|
|
|
|
86
|
|
|
$clientServiceId = sprintf('lexik_paybox.request_cancellation_handler.%s', $name); |
|
87
|
|
|
$container->setDefinition($clientServiceId, $client); |
|
88
|
|
|
|
|
89
|
|
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
private function createResponseHandlerService($name, array $options, ContainerBuilder $container) |
|
93
|
|
|
{ |
|
94
|
|
|
$client = new Definition($container->getParameterBag()->get('lexik_paybox.response_handler.class')); |
|
95
|
|
|
|
|
96
|
|
|
$client->addArgument(new Reference('request_stack')); |
|
97
|
|
|
$client->addArgument(new Reference('logger')); |
|
98
|
|
|
$client->addArgument(new Reference('event_dispatcher')); |
|
99
|
|
|
$client->addArgument($options['parameters']); |
|
100
|
|
|
|
|
101
|
|
|
$client->addTag('monolog.logger', ['channel' => 'payment']); |
|
102
|
|
|
|
|
103
|
|
|
$clientServiceId = sprintf('lexik_paybox.response_handler.%s', $name); |
|
104
|
|
|
$container->setDefinition($clientServiceId, $client); |
|
105
|
|
|
|
|
106
|
|
|
return $this; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
private function createDirecPlusRequestHandlerService($name, array $options, ContainerBuilder $container) |
|
110
|
|
|
{ |
|
111
|
|
|
$client = new Definition($container->getParameterBag()->get('lexik_paybox.direc_plus.request_handler.class')); |
|
112
|
|
|
|
|
113
|
|
|
$client->addArgument($name); |
|
114
|
|
|
$client->addArgument($options['parameters']); |
|
115
|
|
|
$client->addArgument($options['servers']); |
|
116
|
|
|
$client->addArgument(new Reference('logger')); |
|
117
|
|
|
$client->addArgument(new Reference('event_dispatcher')); |
|
118
|
|
|
$client->addArgument(new Reference(sprintf('lexik_paybox.transport.%s', $name))); |
|
119
|
|
|
|
|
120
|
|
|
$client->addTag('monolog.logger', ['channel' => 'payment']); |
|
121
|
|
|
|
|
122
|
|
|
$clientServiceId = sprintf('lexik_paybox.direc_plus.request_handler.%s', $name); |
|
123
|
|
|
$container->setDefinition($clientServiceId, $client); |
|
124
|
|
|
|
|
125
|
|
|
return $this; |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.