1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PaySys\CardPay\DI; |
4
|
|
|
|
5
|
|
|
use Nette\DI\CompilerExtension; |
6
|
|
|
use PaySys\CardPay\Configuration; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class CardPayExtension extends CompilerExtension |
10
|
|
|
{ |
11
|
|
|
const BASE_ROUTE = "CardPay:CardPay:process"; |
12
|
|
|
|
13
|
|
|
/** @var array */ |
14
|
|
|
private $defaults = [ |
15
|
|
|
"mid" => "", |
16
|
|
|
"rurl" => self::BASE_ROUTE, |
17
|
|
|
"key" => "", |
18
|
|
|
"mode" => Configuration::PRODUCTION, |
19
|
|
|
]; |
20
|
|
|
|
21
|
|
|
public function loadConfiguration() |
22
|
|
|
{ |
23
|
|
|
$this->validateConfig($this->defaults); |
|
|
|
|
24
|
|
|
|
25
|
|
|
$builder = $this->getContainerBuilder(); |
26
|
|
|
|
27
|
|
|
$builder->addDefinition($this->prefix('config')) |
28
|
|
|
->setFactory('PaySys\CardPay\Configuration', [ |
29
|
|
|
'mid' => $this->config['mid'], |
30
|
|
|
'rurl' => $this->config['rurl'], |
31
|
|
|
'key' => $this->config['key'], |
32
|
|
|
]) |
33
|
|
|
->addSetup('setMode', [ |
34
|
|
|
$this->config['mode'], |
35
|
|
|
]); |
36
|
|
|
|
37
|
|
|
if (method_exists($builder, 'addFactoryDefinition')) { |
38
|
|
|
$builder->addFactoryDefinition($this->prefix('button')) |
39
|
|
|
->setImplement('PaySys\CardPay\IButtonFactory') |
40
|
|
|
->getResultDefinition() |
41
|
|
|
->setFactory('PaySys\PaySys\Button', [ |
42
|
|
|
'config' => $this->prefix('@config'), |
43
|
|
|
]); |
44
|
|
|
} else { |
45
|
|
|
$builder->addDefinition($this->prefix('button')) |
|
|
|
|
46
|
|
|
->setImplement('PaySys\CardPay\IButtonFactory') |
|
|
|
|
47
|
|
|
->setFactory('PaySys\PaySys\Button', [ |
48
|
|
|
'config' => $this->prefix('@config'), |
49
|
|
|
]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$builder->addDefinition($this->prefix('request')) |
53
|
|
|
->setFactory('PaySys\CardPay\Security\Request'); |
54
|
|
|
|
55
|
|
|
$builder->addDefinition($this->prefix('response')) |
56
|
|
|
->setFactory('PaySys\CardPay\Security\Response'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function beforeCompile() |
60
|
|
|
{ |
61
|
|
|
$builder = $this->getContainerBuilder(); |
62
|
|
|
|
63
|
|
|
if ($this->config['rurl'] === self::BASE_ROUTE) { |
64
|
|
|
if ($builder->hasDefinition('routing.router')) { |
65
|
|
|
$netteRouter = $builder->getDefinition('routing.router'); |
66
|
|
|
$netteRouter->addSetup('$service->prepend(new Nette\Application\Routers\Route(\'cardpay-process\', ?));', [self::BASE_ROUTE]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if ($builder->hasDefinition('nette.presenterFactory')) { |
70
|
|
|
$builder->getDefinition('nette.presenterFactory') |
71
|
|
|
->addSetup('setMapping', [ |
72
|
|
|
['CardPay' => 'PaySys\CardPay\Application\UI\*Presenter'], |
73
|
|
|
]); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.