/
UninstalledSite.php
124 lines (103 loc) · 3.54 KB
/
UninstalledSite.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
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Foundation;
use Flarum\Install\Installer;
use Flarum\Install\InstallServiceProvider;
use Flarum\Locale\LocaleServiceProvider;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Settings\UninstalledSettingsRepository;
use Flarum\User\SessionServiceProvider;
use Illuminate\Config\Repository as ConfigRepository;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Filesystem\FilesystemServiceProvider;
use Illuminate\Validation\ValidationServiceProvider;
use Illuminate\View\Engines\EngineResolver;
use Illuminate\View\Engines\PhpEngine;
use Illuminate\View\FileViewFinder;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
class UninstalledSite implements SiteInterface
{
/**
* @var array
*/
private $paths;
public function __construct(array $paths)
{
$this->paths = $paths;
}
/**
* Create and boot a Flarum application instance.
*
* @return AppInterface
*/
public function bootApp(): AppInterface
{
return new Installer(
$this->bootLaravel()
);
}
private function bootLaravel(): Application
{
$laravel = new Application($this->paths['base'], $this->paths['public']);
$laravel->useStoragePath($this->paths['storage']);
if (isset($this->paths['vendor'])) {
$laravel->useVendorPath($this->paths['vendor']);
}
$laravel->instance('env', 'production');
$laravel->instance('flarum.config', []);
$laravel->instance('config', $config = $this->getIlluminateConfig());
$this->registerLogger($laravel);
$laravel->register(ErrorServiceProvider::class);
$laravel->register(LocaleServiceProvider::class);
$laravel->register(FilesystemServiceProvider::class);
$laravel->register(SessionServiceProvider::class);
$laravel->register(ValidationServiceProvider::class);
$laravel->register(InstallServiceProvider::class);
$laravel->singleton(
SettingsRepositoryInterface::class,
UninstalledSettingsRepository::class
);
$laravel->singleton('view', function ($app) {
$engines = new EngineResolver();
$engines->register('php', function () {
return new PhpEngine();
});
$finder = new FileViewFinder($app->make('files'), []);
$dispatcher = $app->make(Dispatcher::class);
return new \Illuminate\View\Factory(
$engines, $finder, $dispatcher
);
});
$laravel->boot();
return $laravel;
}
/**
* @return ConfigRepository
*/
private function getIlluminateConfig()
{
return new ConfigRepository([
'session' => [
'lifetime' => 120,
'files' => $this->paths['storage'].'/sessions',
'cookie' => 'session'
]
]);
}
private function registerLogger(Application $app)
{
$logPath = $this->paths['storage'].'/logs/flarum-installer.log';
$handler = new StreamHandler($logPath, Logger::DEBUG);
$handler->setFormatter(new LineFormatter(null, null, true, true));
$app->instance('log', new Logger('Flarum Installer', [$handler]));
$app->alias('log', LoggerInterface::class);
}
}