Skip to content

Commit

Permalink
Add compatibility with Nette/DI:3.0@beta
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam committed Oct 27, 2018
1 parent c49992d commit 03e2768
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"ext-soap": "*",
"contributte/thepay-api": "^4.0.0",
"nette/di": "^2.3 || ^3.0",
"nette/application": "^2.3"
"nette/application": "^2.3 || ^3.0"
},
"require-dev": {
"nette/tester": "^2.0.2",
"nette/bootstrap": "^2.4.6",
"nette/bootstrap": "^2.4.6 || ^3.0",
"nette/robot-loader": "^3.0.4",
"tracy/tracy": "^2.5.0",
"phpstan/phpstan": "^0.10.2",
Expand Down
30 changes: 19 additions & 11 deletions src/DI/ThePayExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Contributte\ThePay\IReturnedPayment;
use Contributte\ThePay\MerchantConfig;
use Nette\DI\CompilerExtension;
use Nette\DI\ContainerBuilder;
use Nette\Utils\Validators;

class ThePayExtension extends CompilerExtension
Expand Down Expand Up @@ -55,16 +56,6 @@ public function loadConfiguration(): void
Validators::assertField($this->config['merchant'], 'dataApiPassword', 'string');
Validators::assertField($this->config['merchant'], 'webServicesWsdl', 'string');
Validators::assertField($this->config['merchant'], 'dataWebServicesWsdl', 'string');

$builder = $this->getContainerBuilder();

$builder->addDefinition($this->prefix('merchantConfig'))->setType(MerchantConfig::class);
$builder->addDefinition($this->prefix('helper.dataApi'))->setType(DataApi::class);

$builder->addDefinition($this->prefix('paymentFactory'))->setImplement(IPayment::class);
$builder->addDefinition($this->prefix('permanentPaymentFactory'))->setImplement(IPermanentPayment::class);
$builder->addDefinition($this->prefix('returnedPaymentFactory'))->setImplement(IReturnedPayment::class);
$builder->addDefinition($this->prefix('helper.radioMerchantFactory'))->setImplement(IRadioMerchant::class);
}

public function beforeCompile(): void
Expand All @@ -75,7 +66,15 @@ public function beforeCompile(): void

$builder = $this->getContainerBuilder();

$builder->getDefinition($this->prefix('merchantConfig'))
$merchantConfigDefinition = $builder->addDefinition($this->prefix('merchantConfig'))->setType(MerchantConfig::class);
$builder->addDefinition($this->prefix('helper.dataApi'))->setType(DataApi::class);

$this->registerFactory($builder, $this->prefix('paymentFactory'), IPayment::class);
$this->registerFactory($builder, $this->prefix('permanentPaymentFactory'), IPermanentPayment::class);
$this->registerFactory($builder, $this->prefix('returnedPaymentFactory'), IReturnedPayment::class);
$this->registerFactory($builder, $this->prefix('helper.radioMerchantFactory'), IRadioMerchant::class);

$merchantConfigDefinition
->addSetup(
'$service->isDemo = ?;' . "\n" .
'$service->gateUrl = ?;' . "\n" .
Expand All @@ -98,4 +97,13 @@ public function beforeCompile(): void
);
}

private function registerFactory(ContainerBuilder $builder, string $name, string $interface): void
{
if (method_exists($builder, 'addFactoryDefinition')) {
$builder->addFactoryDefinition($name)->setImplement($interface);
} else {
$builder->addDefinition($name)->setImplement($interface);
}
}

}
3 changes: 2 additions & 1 deletion tests/config/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
parameters:
ignoreErrors: []
ignoreErrors:
- '#Method Nette\\DI\\Definitions\\ServiceDefinition::setImplement\(\) invoked with 1 parameter, 0 required\.#'

0 comments on commit 03e2768

Please sign in to comment.