-
Notifications
You must be signed in to change notification settings - Fork 6
/
RpayRatePay.php
executable file
·171 lines (153 loc) · 5.53 KB
/
RpayRatePay.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/**
* Copyright (c) 2020 Ratepay GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace RpayRatePay;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
use Monolog\Processor\PsrLogMessageProcessor;
use RpayRatePay\Bootstrap\AbstractBootstrap;
use RpayRatePay\Bootstrap\Configuration;
use RpayRatePay\Bootstrap\Database;
use RpayRatePay\Bootstrap\OrderAttribute;
use RpayRatePay\Bootstrap\OrderDetailAttributes;
use RpayRatePay\Bootstrap\OrderStatus;
use RpayRatePay\Bootstrap\PaymentMeans;
use RpayRatePay\Bootstrap\ProfileConfig;
use RpayRatePay\Bootstrap\UserAttribute;
use RpayRatePay\Services\Logger\FileLogger;
use Shopware\Components\Plugin;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class RpayRatePay extends Plugin
{
public static function isPackage()
{
return file_exists(self::getPackageVendorAutoload());
}
public static function getPackageVendorAutoload()
{
return __DIR__ . '/vendor/autoload.php';
}
public function build(ContainerBuilder $container)
{
if ($container->hasParameter('rpay_rate_pay.logger.max_files') === false) {
$container->setParameter('rpay_rate_pay.logger.max_files', 5);
$container->setParameter('rpay_rate_pay.logger.level', Logger::DEBUG);
}
parent::build($container);
}
/**
* @param Plugin\Context\InstallContext $context
* @return AbstractBootstrap[]
*/
protected function getBootstrapClasses(Plugin\Context\InstallContext $context)
{
/** @var AbstractBootstrap[] $bootstrapper */
$bootstrapper = [
new OrderAttribute(),
new OrderDetailAttributes(),
new Database(),
new ProfileConfig(),
new PaymentMeans(),
new OrderStatus(),
new Configuration(),
new UserAttribute()
];
if($this->container->has('ratepay.logger')) {
$logger = $this->container->get('ratepay.logger');
} else {
// create a new logger as described in services/logging.xml
$logger = new Logger(
'ratepay',
[new RotatingFileHandler(
$this->container->getParameter('kernel.logs_dir') . '/ratepay_' . $this->container->getParameter('kernel.environment') . '.log',
5,
Logger::DEBUG
)],
[new PsrLogMessageProcessor()]
);
}
foreach ($bootstrapper as $bootstrap) {
$bootstrap->setContext($context);
$bootstrap->setLogger($logger);
$bootstrap->setContainer($this->container);
$bootstrap->setPluginDir($this->getPath());
}
return $bootstrapper;
}
public function install(Plugin\Context\InstallContext $context)
{
foreach ($this->getBootstrapClasses($context) as $bootstrap) {
$bootstrap->preInstall();
}
foreach ($this->getBootstrapClasses($context) as $bootstrap) {
$bootstrap->install();
}
foreach ($this->getBootstrapClasses($context) as $bootstrap) {
$bootstrap->postInstall();
}
parent::install($context);
}
public function update(Plugin\Context\UpdateContext $context)
{
foreach ($this->getBootstrapClasses($context) as $bootstrap) {
$bootstrap->preUpdate();
}
foreach ($this->getBootstrapClasses($context) as $bootstrap) {
$bootstrap->update();
}
foreach ($this->getBootstrapClasses($context) as $bootstrap) {
$bootstrap->postUpdate();
}
parent::update($context);
$context->scheduleClearCache($context::CACHE_LIST_ALL);
}
public function uninstall(Plugin\Context\UninstallContext $context)
{
foreach ($this->getBootstrapClasses($context) as $bootstrap) {
$bootstrap->preUninstall();
}
foreach ($this->getBootstrapClasses($context) as $bootstrap) {
$bootstrap->uninstall($context->keepUserData());
}
foreach ($this->getBootstrapClasses($context) as $bootstrap) {
$bootstrap->postUninstall();
}
parent::uninstall($context);
$context->scheduleClearCache($context::CACHE_LIST_ALL);
}
public function deactivate(Plugin\Context\DeactivateContext $context)
{
foreach ($this->getBootstrapClasses($context) as $bootstrap) {
$bootstrap->preDeactivate();
}
foreach ($this->getBootstrapClasses($context) as $bootstrap) {
$bootstrap->deactivate();
}
foreach ($this->getBootstrapClasses($context) as $bootstrap) {
$bootstrap->postDeactivate();
}
parent::deactivate($context);
$context->scheduleClearCache($context::CACHE_LIST_ALL);
}
public function activate(Plugin\Context\ActivateContext $context)
{
foreach ($this->getBootstrapClasses($context) as $bootstrap) {
$bootstrap->preActivate();
}
foreach ($this->getBootstrapClasses($context) as $bootstrap) {
$bootstrap->activate();
}
foreach ($this->getBootstrapClasses($context) as $bootstrap) {
$bootstrap->postActivate();
}
parent::activate($context);
$context->scheduleClearCache($context::CACHE_LIST_ALL);
}
}
if (RpayRatePay::isPackage()) {
require_once RpayRatePay::getPackageVendorAutoload();
}