Skip to content

Commit 05740be

Browse files
committed
Assert config in ThePayExtension
1 parent 755aa38 commit 05740be

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/DI/ThePayExtension.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Trejjam\ThePay\DI;
55

6+
use Nette\Utils\Validators;
67
use Trejjam;
78

89
class ThePayExtension extends Trejjam\BaseExtension\DI\BaseExtension
@@ -11,8 +12,8 @@ class ThePayExtension extends Trejjam\BaseExtension\DI\BaseExtension
1112
'demo' => true,
1213
'merchant' => [
1314
'gateUrl' => 'https://www.thepay.cz/gate/',
14-
'merchantId' => '',
15-
'accountId' => '',
15+
'merchantId' => null,
16+
'accountId' => null,
1617
'password' => '',
1718
'dataApiPassword' => '',
1819
'webServicesWsdl' => 'https://www.thepay.cz/gate/api/gate-api.wsdl',
@@ -31,24 +32,35 @@ class ThePayExtension extends Trejjam\BaseExtension\DI\BaseExtension
3132
];
3233

3334
protected $classesDefinition = [
34-
'merchantConfig' => 'Trejjam\ThePay\MerchantConfig',
35-
'helper.dataApi' => 'Trejjam\ThePay\Helper\DataApi',
35+
'merchantConfig' => Trejjam\ThePay\MerchantConfig::class,
36+
'helper.dataApi' => Trejjam\ThePay\Helper\DataApi::class,
3637
];
3738

3839
protected $factoriesDefinition = [
39-
'paymentFactory' => 'Trejjam\ThePay\IPayment',
40-
'permanentPaymentFactory' => 'Trejjam\ThePay\IPermanentPayment',
41-
'returnedPaymentFactory' => 'Trejjam\ThePay\IReturnedPayment',
42-
'helper.radioMerchantFactory' => 'Trejjam\ThePay\Helper\IRadioMerchant',
40+
'paymentFactory' => Trejjam\ThePay\IPayment::class,
41+
'permanentPaymentFactory' => Trejjam\ThePay\IPermanentPayment::class,
42+
'returnedPaymentFactory' => Trejjam\ThePay\IReturnedPayment::class,
43+
'helper.radioMerchantFactory' => Trejjam\ThePay\Helper\IRadioMerchant::class,
4344
];
4445

4546
public function loadConfiguration(bool $validateConfig = true) : void
4647
{
4748
parent::loadConfiguration();
4849

50+
Validators::assertField($this->config, 'demo', 'bool');
51+
4952
if ($this->config['demo']) {
5053
$this->config['merchant'] = $this->merchantDemo;
5154
}
55+
56+
Validators::assertField($this->config, 'merchant', 'array');
57+
Validators::assertField($this->config['merchant'], 'gateUrl', 'string');
58+
Validators::assertField($this->config['merchant'], 'merchantId', 'int');
59+
Validators::assertField($this->config['merchant'], 'accountId', 'int');
60+
Validators::assertField($this->config['merchant'], 'password', 'string');
61+
Validators::assertField($this->config['merchant'], 'dataApiPassword', 'string');
62+
Validators::assertField($this->config['merchant'], 'webServicesWsdl', 'string');
63+
Validators::assertField($this->config['merchant'], 'dataWebServicesWsdl', 'string');
5264
}
5365

5466
public function beforeCompile() : void
@@ -72,8 +84,8 @@ public function beforeCompile() : void
7284
[
7385
$this->config['demo'],
7486
$merchantConfig['gateUrl'],
75-
intval($merchantConfig['merchantId']),
76-
intval($merchantConfig['accountId']),
87+
$merchantConfig['merchantId'],
88+
$merchantConfig['accountId'],
7789
$merchantConfig['password'],
7890
$merchantConfig['dataApiPassword'],
7991
$merchantConfig['webServicesWsdl'],

0 commit comments

Comments
 (0)