-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bootstrap.php
118 lines (97 loc) · 3.9 KB
/
Bootstrap.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
<?php
namespace ProVallo\Plugins\Backend;
use ProVallo\Components\Plugin\LifecycleResult;
use ProVallo\Core;
use ProVallo\Plugins\Backend\Commands\BackendBuildCommand;
use ProVallo\Plugins\Backend\Commands\BackendRegisterCommand;
use ProVallo\Plugins\Backend\Components\Auth;
use ProVallo\Plugins\Backend\Components\Config\Manager;
use ProVallo\Plugins\Backend\Components\ModelValidator;
use ProVallo\Plugins\Backend\Components\Permission\PermissionService;
use ProVallo\Plugins\Backend\Job\BuildJob;
use ProVallo\Plugins\Backend\Job\CreateConfigJob;
class Bootstrap extends \ProVallo\Components\Plugin\Bootstrap
{
public function install ()
{
$this->installDB();
$permission = new PermissionService();
$permission->add('user.backend.access', true, 'Allow the user to login into backend.');
return (new LifecycleResult(LifecycleResult::TYPE_INSTALL, true))
->addJob(new CreateConfigJob())
->addJob(new BuildJob());
}
public function update ($previousVersion)
{
$this->installDB();
$permission = new PermissionService();
$permission->add('user.backend.access', true, 'Allow the user to login into backend.');
return (new LifecycleResult(LifecycleResult::TYPE_UPDATE, true))
->addJob(new CreateConfigJob())
->addJob(new BuildJob());
}
public function execute ()
{
if (Core::instance()->getApi() === Core::API_WEB)
{
// Register custom services
Core::di()->registerShared('auth', function ()
{
return new Auth();
});
Core::di()->registerShared('permission', function ()
{
return new PermissionService();
});
Core::events()->subscribe('core.route.register', function ()
{
Core::instance()->registerModule('backend', [
'controller' => [
'namespace' => 'ProVallo\\Controllers\\Backend\\',
'class_suffix' => 'Controller',
'method_suffix' => 'Action'
]
]);
// Redirect "/backend" to "/backend/"
Core::instance()->get('/backend', function ($request, $response)
{
return $response->withRedirect('/backend/');
});
// Define the default backend path
Core::instance()->get('/backend/', 'backend:Index:index');
// Register all backend controllers
$this->registerController('Backend', 'Index');
$this->registerController('Backend', 'User');
$this->registerController('Backend', 'Config');
$this->registerController('Backend', 'Group');
$this->registerController('Backend', 'Permission');
$this->registerController('Backend', 'Plugin');
});
}
if (Core::instance()->getApi() === CORE::API_CONSOLE)
{
// Register custom commands
Core::events()->subscribe('console.register', function ()
{
return [
new BackendRegisterCommand(),
new BackendBuildCommand()
];
});
}
Core::di()->registerShared('backend.config', function ()
{
return new Manager();
});
Core::di()->registerShared('modelValidator', function ()
{
return new ModelValidator();
});
}
public static function getConfig ()
{
$plugin = Core::plugins()->get('Backend');
$manager = new Manager();
return $manager->get($plugin);
}
}