9
9
namespace Trejjam \ThePay \DI ;
10
10
11
11
use Nette ,
12
- Tp ;
12
+ Tp ,
13
+ Trejjam ;
13
14
14
- class ThePayExtension extends Nette \ DI \CompilerExtension
15
+ class ThePayExtension extends Trejjam \ BaseExtension \ DI \BaseExtension
15
16
{
16
- protected $ defaults = [
17
+ protected $ default = [
17
18
'demo ' => TRUE ,
18
19
'merchant ' => [
19
20
'gateUrl ' => 'https://www.thepay.cz/gate/ ' ,
@@ -36,74 +37,50 @@ class ThePayExtension extends Nette\DI\CompilerExtension
36
37
'dataWebServicesWsdl ' => 'https://www.thepay.cz/demo-gate/api/data-demo.wsdl ' ,
37
38
];
38
39
39
- public function loadConfiguration ()
40
- {
41
- parent ::loadConfiguration ();
42
-
43
- $ builder = $ this ->getContainerBuilder ();
44
- $ config = $ this ->createConfig ();
45
-
46
- $ classesDefinition = [
47
- 'merchantConfig ' => 'Tp\MerchantConfig ' ,
48
- 'helper.dataApi ' => 'Trejjam\ThePay\Helper\DataApi ' ,
49
- ];
50
-
51
- $ factoriesDefinition = [
52
- 'paymentFactory ' => 'Trejjam\ThePay\IPayment ' ,
53
- 'permanentPaymentFactory ' => 'Trejjam\ThePay\IPermanentPayment ' ,
54
- 'returnedPaymentFactory ' => 'Trejjam\ThePay\IReturnedPayment ' ,
55
- 'helper.radioMerchantFactory ' => 'Trejjam\ThePay\Helper\IRadioMerchant ' ,
56
- ];
57
-
58
- /** @var Nette\DI\ServiceDefinition[] $classes */
59
- $ classes = [];
60
-
61
- foreach ($ classesDefinition as $ k => $ v ) {
62
- $ classes [$ k ] = $ builder ->addDefinition ($ this ->prefix ($ k ))
63
- ->setClass ($ v );
64
- }
65
-
66
- /** @var Nette\DI\ServiceDefinition[] $factories */
67
- $ factories = [];
40
+ protected $ classesDefinition = [
41
+ 'merchantConfig ' => 'Tp\MerchantConfig ' ,
42
+ 'helper.dataApi ' => 'Trejjam\ThePay\Helper\DataApi ' ,
43
+ ];
68
44
69
- foreach ($ factoriesDefinition as $ k => $ v ) {
70
- $ factories [$ k ] = $ builder ->addDefinition ($ this ->prefix ($ k ))
71
- ->setImplement ($ v );
72
- }
73
- }
45
+ protected $ factoriesDefinition = [
46
+ 'paymentFactory ' => 'Trejjam\ThePay\IPayment ' ,
47
+ 'permanentPaymentFactory ' => 'Trejjam\ThePay\IPermanentPayment ' ,
48
+ 'returnedPaymentFactory ' => 'Trejjam\ThePay\IReturnedPayment ' ,
49
+ 'helper.radioMerchantFactory ' => 'Trejjam\ThePay\Helper\IRadioMerchant ' ,
50
+ ];
74
51
75
52
public function beforeCompile ()
76
53
{
77
54
parent ::beforeCompile ();
78
55
79
- $ builder = $ this ->getContainerBuilder ();
80
56
$ config = $ this ->createConfig ();
81
57
$ merchantConfig = $ config ['merchant ' ];
82
58
83
- $ builder ->getDefinition ($ this ->prefix ('merchantConfig ' ))
84
- ->addSetup (
85
- '$service->gateUrl = ?; ' . "\n" .
86
- '$service->merchantId = ?; ' . "\n" .
87
- '$service->accountId = ?; ' . "\n" .
88
- '$service->password = ?; ' . "\n" .
89
- '$service->dataApiPassword = ?; ' . "\n" .
90
- '$service->webServicesWsdl = ?; ' . "\n" .
91
- '$service->dataWebServicesWsdl = ? ' ,
92
- [
93
- $ merchantConfig ['gateUrl ' ],
94
- $ merchantConfig ['merchantId ' ],
95
- $ merchantConfig ['accountId ' ],
96
- $ merchantConfig ['password ' ],
97
- $ merchantConfig ['dataApiPassword ' ],
98
- $ merchantConfig ['webServicesWsdl ' ],
99
- $ merchantConfig ['dataWebServicesWsdl ' ],
100
- ]);
59
+ $ classes = $ this ->getClasses ();
60
+
61
+ $ classes ['merchantConfig ' ]
62
+ ->addSetup (
63
+ '$service->gateUrl = ?; ' . "\n" .
64
+ '$service->merchantId = ?; ' . "\n" .
65
+ '$service->accountId = ?; ' . "\n" .
66
+ '$service->password = ?; ' . "\n" .
67
+ '$service->dataApiPassword = ?; ' . "\n" .
68
+ '$service->webServicesWsdl = ?; ' . "\n" .
69
+ '$service->dataWebServicesWsdl = ? ' ,
70
+ [
71
+ $ merchantConfig ['gateUrl ' ],
72
+ $ merchantConfig ['merchantId ' ],
73
+ $ merchantConfig ['accountId ' ],
74
+ $ merchantConfig ['password ' ],
75
+ $ merchantConfig ['dataApiPassword ' ],
76
+ $ merchantConfig ['webServicesWsdl ' ],
77
+ $ merchantConfig ['dataWebServicesWsdl ' ],
78
+ ]);
101
79
}
102
80
103
81
protected function createConfig ()
104
82
{
105
- $ config = $ this ->getConfig ($ this ->defaults );
106
- Nette \Utils \Validators::assert ($ config , 'array ' );
83
+ $ config = parent ::createConfig ();
107
84
if ($ config ['demo ' ]) {
108
85
$ config ['merchant ' ] = $ this ->merchantDemo ;
109
86
}
0 commit comments