-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
75 lines (68 loc) · 2.3 KB
/
bootstrap.php
File metadata and controls
75 lines (68 loc) · 2.3 KB
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
<?php
use SalesRender\Plugin\Components\Batch\BatchContainer;
use SalesRender\Plugin\Components\Db\Components\Connector;
use SalesRender\Plugin\Components\Info\Developer;
use SalesRender\Plugin\Components\Info\Info;
use SalesRender\Plugin\Components\Info\PluginType;
use SalesRender\Plugin\Components\Purpose\MacrosPluginClass;
use SalesRender\Plugin\Components\Purpose\PluginEntity;
use SalesRender\Plugin\Components\Purpose\PluginPurpose;
use SalesRender\Plugin\Components\Settings\Settings;
use SalesRender\Plugin\Components\Translations\Translator;
use SalesRender\Plugin\Instance\Excel\OrdersHandler;
use SalesRender\Plugin\Instance\Excel\Forms\BatchForm_1;
use SalesRender\Plugin\Instance\Excel\Forms\SettingsForm;
use Medoo\Medoo;
use XAKEPEHOK\Path\Path;
if (!empty($_ENV['APP_SENTRY'])) {
\Sentry\init(['dsn' => $_ENV['APP_SENTRY']]);
}
# 1. Configure DB (for SQLite *.db file and parent directory should be writable)
switch ($_ENV['DATABASE_TYPE'] ?? 'sqlite') {
default:
case 'sqlite':
$params = [
'database_type' => 'sqlite',
'database_file' => Path::root()->down('db/database.db')
];
break;
case 'mysql':
$params = [
'database_type' => 'mysql',
'server' => $_ENV['DATABASE_SERVER'],
'database_name' => $_ENV['DATABASE_NAME'],
'username' => $_ENV['DATABASE_USER'],
'password' => $_ENV['DATABASE_PASS']
];
break;
}
Connector::config(new Medoo($params));
# 2. Set plugin default language
Translator::config('ru_RU');
# 3. Configure info about plugin
Info::config(
new PluginType(PluginType::MACROS),
fn() => Translator::get('info', 'PLUGIN_NAME'),
fn() => Translator::get('info', 'PLUGIN_DESCRIPTION'),
new PluginPurpose(
new MacrosPluginClass(MacrosPluginClass::CLASS_HANDLER),
new PluginEntity(PluginEntity::ENTITY_ORDER)
),
new Developer(
'SalesRender',
'support@salesrender.com',
'salesrender.com',
)
);
# 4. Configure settings form
Settings::setForm(fn() => new SettingsForm());
# 6. Configure batch forms and handler
BatchContainer::config(
function (int $number) {
switch ($number) {
case 1: return new BatchForm_1();
default: return null;
}
},
new OrdersHandler()
);