-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBilliePayment.php
129 lines (117 loc) · 4.28 KB
/
BilliePayment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
namespace BilliePayment;
use BilliePayment\Bootstrap\AbstractBootstrap;
use BilliePayment\Bootstrap\Attributes\OrderAttributes;
use BilliePayment\Bootstrap\Attributes\PaymentMethodAttributes;
use BilliePayment\Bootstrap\Attributes\UserAddressAttributes;
use BilliePayment\Bootstrap\Attributes\UserAttributes;
use BilliePayment\Bootstrap\PaymentMethods;
use BilliePayment\Compiler\FileLoggerPass;
use Shopware\Components\Plugin;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class BilliePayment extends Plugin
{
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new FileLoggerPass($this->getContainerPrefix()));
}
public function install(Plugin\Context\InstallContext $context)
{
$bootstrapClasses = $this->getBootstrapClasses($context);
foreach ($bootstrapClasses as $bootstrap) {
$bootstrap->preInstall();
}
foreach ($bootstrapClasses as $bootstrap) {
$bootstrap->install();
}
foreach ($bootstrapClasses as $bootstrap) {
$bootstrap->postInstall();
}
parent::install($context);
}
public function update(Plugin\Context\UpdateContext $context)
{
$bootstrapClasses = $this->getBootstrapClasses($context);
foreach ($bootstrapClasses as $bootstrap) {
$bootstrap->preUpdate();
}
foreach ($bootstrapClasses as $bootstrap) {
$bootstrap->update();
}
foreach ($bootstrapClasses as $bootstrap) {
$bootstrap->postUpdate();
}
parent::update($context);
}
public function uninstall(Plugin\Context\UninstallContext $context)
{
$bootstrapClasses = $this->getBootstrapClasses($context);
foreach ($bootstrapClasses as $bootstrap) {
$bootstrap->preUninstall();
}
foreach ($bootstrapClasses as $bootstrap) {
$bootstrap->uninstall($context->keepUserData());
}
foreach ($bootstrapClasses as $bootstrap) {
$bootstrap->postUninstall();
}
}
public function deactivate(Plugin\Context\DeactivateContext $context)
{
$bootstrapClasses = $this->getBootstrapClasses($context);
foreach ($bootstrapClasses as $bootstrap) {
$bootstrap->preDeactivate();
}
foreach ($bootstrapClasses as $bootstrap) {
$bootstrap->deactivate();
}
foreach ($bootstrapClasses as $bootstrap) {
$bootstrap->postDeactivate();
}
parent::deactivate($context);
$context->scheduleClearCache($context::CACHE_LIST_ALL);
}
public function activate(Plugin\Context\ActivateContext $context)
{
$bootstrapClasses = $this->getBootstrapClasses($context);
foreach ($bootstrapClasses as $bootstrap) {
$bootstrap->preActivate();
}
foreach ($bootstrapClasses as $bootstrap) {
$bootstrap->activate();
}
foreach ($bootstrapClasses as $bootstrap) {
$bootstrap->postActivate();
}
parent::activate($context);
$context->scheduleClearCache($context::CACHE_LIST_ALL);
}
/**
* @return AbstractBootstrap[]
*/
protected function getBootstrapClasses(Plugin\Context\InstallContext $context)
{
// install payment-method before the payment-method-attribute, cause the attributes cache will be cleared,
// but the model-class has been already loaded. So this will ends in an error, when the columns in the database
// does not exist anymore e.g. after an uninstall
/** @var AbstractBootstrap[] $bootstrapper */
$bootstrapper = [
new PaymentMethods(),
new PaymentMethodAttributes(),
new OrderAttributes(),
new UserAddressAttributes(),
new UserAttributes(),
];
// initialize all bootstraps
foreach ($bootstrapper as $bootstrap) {
$bootstrap->setContext($context);
$bootstrap->setContainer($this->container);
$bootstrap->setPluginDir($this->getPath());
}
return $bootstrapper;
}
}
if (!class_exists(\Billie\Sdk\Model\Order::class)) {
require_once __DIR__ . '/vendor/autoload.php';
}