-
-
Notifications
You must be signed in to change notification settings - Fork 828
/
AdminServiceProvider.php
96 lines (80 loc) · 2.46 KB
/
AdminServiceProvider.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
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Admin;
use Flarum\Event\ExtensionWasDisabled;
use Flarum\Event\ExtensionWasEnabled;
use Flarum\Event\SettingWasSet;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Http\Handler\RouteHandlerFactory;
use Flarum\Http\RouteCollection;
class AdminServiceProvider extends AbstractServiceProvider
{
/**
* {@inheritdoc}
*/
public function register()
{
$this->app->singleton(UrlGenerator::class, function () {
return new UrlGenerator($this->app, $this->app->make('flarum.admin.routes'));
});
$this->app->singleton('flarum.admin.routes', function () {
return new RouteCollection;
});
}
/**
* {@inheritdoc}
*/
public function boot()
{
$this->populateRoutes($this->app->make('flarum.admin.routes'));
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum.admin');
$this->flushWebAppAssetsWhenThemeChanged();
$this->flushWebAppAssetsWhenExtensionsChanged();
}
/**
* Populate the forum client routes.
*
* @param RouteCollection $routes
*/
protected function populateRoutes(RouteCollection $routes)
{
$route = $this->app->make(RouteHandlerFactory::class);
$routes->get(
'/',
'index',
$route->toController(Controller\WebAppController::class)
);
}
protected function flushWebAppAssetsWhenThemeChanged()
{
$this->app->make('events')->listen(SettingWasSet::class, function (SettingWasSet $event) {
if (preg_match('/^theme_|^custom_less$/i', $event->key)) {
$this->getWebAppAssets()->flushCss();
}
});
}
protected function flushWebAppAssetsWhenExtensionsChanged()
{
$events = $this->app->make('events');
$events->listen(ExtensionWasEnabled::class, [$this, 'flushWebAppAssets']);
$events->listen(ExtensionWasDisabled::class, [$this, 'flushWebAppAssets']);
}
public function flushWebAppAssets()
{
$this->getWebAppAssets()->flush();
}
/**
* @return \Flarum\Http\WebApp\WebAppAssets
*/
protected function getWebAppAssets()
{
return $this->app->make(WebApp::class)->getAssets();
}
}