-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.php
149 lines (121 loc) · 4.71 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
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
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Flarum\Core;
use Flarum\Core\Application;
use Illuminate\Cache\FileStore;
use Illuminate\Cache\Repository;
use Illuminate\Config\Repository as ConfigRepository;
use Illuminate\Filesystem\Filesystem;
define('FLARUM_START', microtime(true));
require __DIR__ . '/vendor/autoload.php';
// franzliedke/studio currently doesn't autoload files (see issue below), so we
// will need to load them manually if we're using studio.
// https://github.com/franzliedke/studio/issues/29
if (file_exists(__DIR__ . '/core')) {
require __DIR__ . '/core/src/helpers.php';
require __DIR__ . '/core/vendor/swiftmailer/swiftmailer/lib/swift_required.php';
}
$app = new Application(realpath(__DIR__));
$app->instance('path.public', __DIR__.'/..');
Illuminate\Container\Container::setInstance($app);
if (file_exists($configFile = __DIR__.'/../config.php')) {
$app->instance('flarum.config', include $configFile);
}
date_default_timezone_set('UTC');
$app->instance('config', $config = new ConfigRepository([
'view' => [
'paths' => [
realpath(base_path('resources/views'))
],
'compiled' => realpath(storage_path().'/framework/views'),
],
'mail' => [
'driver' => 'mail',
],
'cache' => [
'default' => 'file',
'stores' => [
'file' => [
'driver' => 'file',
'path' => storage_path().'/framework/cache',
],
],
'prefix' => 'flarum',
],
'filesystems' => [
'default' => 'local',
'cloud' => 's3',
'disks' => [
'flarum-avatars' => [
'driver' => 'local',
'root' => public_path('assets/avatars')
],
],
],
]));
$logger = new Monolog\Logger($app->environment());
$logPath = $app->storagePath() . '/logs/flarum.log';
$handler = new \Monolog\Handler\StreamHandler($logPath, Monolog\Logger::DEBUG);
$handler->setFormatter(new \Monolog\Formatter\LineFormatter(null, null, true, true));
$logger->pushHandler($handler);
$app->instance('log', $logger);
$app->alias('log', 'Psr\Log\LoggerInterface');
$app->singleton('cache', function ($app) {
$store = new FileStore(new Filesystem(), storage_path('framework/cache'));
$repository = new Repository($store);
$repository->setEventDispatcher($app->make('events'));
return $repository;
});
$app->alias('cache', 'Illuminate\Contracts\Cache\Repository');
$serviceProviders = [
'Flarum\Core\DatabaseServiceProvider',
'Flarum\Core\Settings\SettingsServiceProvider',
'Flarum\Locale\LocaleServiceProvider',
'Illuminate\Bus\BusServiceProvider',
'Illuminate\Filesystem\FilesystemServiceProvider',
'Illuminate\Hashing\HashServiceProvider',
'Illuminate\Mail\MailServiceProvider',
'Illuminate\View\ViewServiceProvider',
'Illuminate\Events\EventServiceProvider',
'Illuminate\Validation\ValidationServiceProvider',
];
foreach ($serviceProviders as $provider) {
$app->register(new $provider($app));
}
if (Core::isInstalled()) {
$settings = $app->make('Flarum\Core\Settings\SettingsRepository');
$app->register(new \Flarum\Core\CoreServiceProvider($app));
$config->set('mail.driver', Core::config('mail_driver'));
$config->set('mail.host', Core::config('mail_host'));
$config->set('mail.port', Core::config('mail_port'));
$config->set('mail.from.address', Core::config('mail_from'));
$config->set('mail.from.name', Core::config('forum_title'));
$config->set('mail.encryption', Core::config('mail_encryption'));
$config->set('mail.username', Core::config('mail_username'));
$config->set('mail.password', Core::config('mail_password'));
// Register extensions and tell them to listen for events
$app->register(new \Flarum\Support\ExtensionsServiceProvider($app));
}
$app->boot();
// If the version stored in the database doesn't match the version of the
// code, then run the upgrade script (migrations). This is temporary - a
// proper, more secure upgrade method is planned.
if (Core::isInstalled() && $settings->get('version') !== $app::VERSION) {
$input = new \Symfony\Component\Console\Input\StringInput('');
$output = new \Symfony\Component\Console\Output\BufferedOutput;
app('Flarum\Console\UpgradeCommand')->run($input, $output);
$settings->set('version', $app::VERSION);
app('flarum.formatter')->flush();
$forum = app('Flarum\Forum\Actions\ClientAction');
$forum->flushAssets();
$admin = app('Flarum\Admin\Actions\ClientAction');
$admin->flushAssets();
}
return $app;