-
Notifications
You must be signed in to change notification settings - Fork 20
/
Plugin.php
135 lines (126 loc) · 4.97 KB
/
Plugin.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
<?php namespace Lovata\Toolbox;
use Lang;
use System\Classes\PluginBase;
use Lovata\Toolbox\Components\Pagination;
use Lovata\Toolbox\Classes\Console\ToolBoxHelper;
use Lovata\Toolbox\Classes\Console\CreateAll;
use Lovata\Toolbox\Classes\Console\CreatePlugin;
use Lovata\Toolbox\Classes\Console\CreateModel;
use Lovata\Toolbox\Classes\Console\CreateModelColumn;
use Lovata\Toolbox\Classes\Console\CreateModelField;
use Lovata\Toolbox\Classes\Console\CreateController;
use Lovata\Toolbox\Classes\Console\CreateMigration;
use Lovata\Toolbox\Classes\Console\CreateComponentData;
use Lovata\Toolbox\Classes\Console\CreateComponentList;
use Lovata\Toolbox\Classes\Console\CreateComponentPage;
use Lovata\Toolbox\Classes\Console\CreateItem;
use Lovata\Toolbox\Classes\Console\CreateCollection;
use Lovata\Toolbox\Classes\Console\CreateEventModel;
use Lovata\Toolbox\Classes\Console\CreateStore;
use Lovata\Toolbox\Classes\Console\CreateExtendBackendMenuHandler;
use Lovata\Toolbox\Classes\Console\CreateExtendModelFieldsHandler;
use Lovata\Toolbox\Classes\Console\CreateExtendModelColumnsHandler;
/**
* Class Plugin
* @package Lovata\Toolbox
* @author Andrey Kharanenka, [email protected], LOVATA Group
*/
class Plugin extends PluginBase
{
/**
* @return array
*/
public function registerComponents()
{
return [
Pagination::class => 'Pagination',
];
}
/**
* @return array
*/
public function registerSettings()
{
return [
'config' => [
'label' => 'lovata.toolbox::lang.field.site_settings',
'icon' => 'icon-cogs',
'description' => 'lovata.toolbox::lang.field.site_settings_description',
'class' => 'Lovata\Toolbox\Models\Settings',
'order' => 300,
'permissions' => [
'toolbox-menu-settings',
],
],
];
}
/**
* Extending twig
* @return array
*/
public function registerMarkupTags()
{
return [
'functions' => [
'choice' => function ($sLangString, $iNumber) {
return $this->twigChoice($sLangString, $iNumber);
},
],
'filters' => [
'phone' => [$this, 'applyPhoneFilter'],
],
];
}
/**
* Plugin boot method
*/
public function boot()
{
if (env('APP_ENV') == 'testing') {
$this->app->bind(\Lovata\Toolbox\Classes\Item\TestItem::class, \Lovata\Toolbox\Classes\Item\TestItem::class);
$this->app->bind(\Lovata\Toolbox\Classes\Collection\TestCollection::class, \Lovata\Toolbox\Classes\Collection\TestCollection::class);
}
}
/**
* Register commands
*/
public function register()
{
$this->registerConsoleCommand('toolbox:helper', ToolBoxHelper::class);
$this->registerConsoleCommand('toolbox:create.all', CreateAll::class);
$this->registerConsoleCommand('toolbox:create.plugin', CreatePlugin::class);
$this->registerConsoleCommand('toolbox:create.model', CreateModel::class);
$this->registerConsoleCommand('toolbox:create.model.columns', CreateModelColumn::class);
$this->registerConsoleCommand('toolbox:create.model.fields', CreateModelField::class);
$this->registerConsoleCommand('toolbox:create.controller', CreateController::class);
$this->registerConsoleCommand('toolbox:create.migration', CreateMigration::class);
$this->registerConsoleCommand('toolbox:create.component.data', CreateComponentData::class);
$this->registerConsoleCommand('toolbox:create.component.list', CreateComponentList::class);
$this->registerConsoleCommand('toolbox:create.component.page', CreateComponentPage::class);
$this->registerConsoleCommand('toolbox:create.item', CreateItem::class);
$this->registerConsoleCommand('toolbox:create.collection', CreateCollection::class);
$this->registerConsoleCommand('toolbox:create.event.model', CreateEventModel::class);
$this->registerConsoleCommand('toolbox:create.store', CreateStore::class);
$this->registerConsoleCommand('toolbox:create.event.menu', CreateExtendBackendMenuHandler::class);
$this->registerConsoleCommand('toolbox:create.event.fields', CreateExtendModelFieldsHandler::class);
$this->registerConsoleCommand('toolbox:create.event.columns', CreateExtendModelColumnsHandler::class);
}
/**
* Apply Lang::choice method to string
* @param string $sLangString
* @param int $iNumber
* @return string
*/
protected function twigChoice($sLangString, $iNumber)
{
return Lang::choice($sLangString, $iNumber);
}
/**
* Deletes all characters from string except digits and plus
* @param $sValue
* @return string
*/
public function applyPhoneFilter($sValue) {
return preg_replace("%[^\d\+]%", '', $sValue);
}
}