1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* webtrees: online genealogy |
5
|
|
|
* Copyright (C) 2019 webtrees development team |
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU General Public License as published by |
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* You should have received a copy of the GNU General Public License |
15
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
declare(strict_types=1); |
19
|
|
|
|
20
|
|
|
namespace Fisharebest\Webtrees; |
21
|
|
|
|
22
|
|
|
use Closure; |
23
|
|
|
use ErrorException; |
24
|
|
|
use Fisharebest\Webtrees\Http\Middleware\BootModules; |
25
|
|
|
use Fisharebest\Webtrees\Http\Middleware\CheckCsrf; |
26
|
|
|
use Fisharebest\Webtrees\Http\Middleware\CheckForMaintenanceMode; |
27
|
|
|
use Fisharebest\Webtrees\Http\Middleware\ClientIp; |
28
|
|
|
use Fisharebest\Webtrees\Http\Middleware\DoHousekeeping; |
29
|
|
|
use Fisharebest\Webtrees\Http\Middleware\EmitResponse; |
30
|
|
|
use Fisharebest\Webtrees\Http\Middleware\HandleExceptions; |
31
|
|
|
use Fisharebest\Webtrees\Http\Middleware\LoadRoutes; |
32
|
|
|
use Fisharebest\Webtrees\Http\Middleware\NoRouteFound; |
33
|
|
|
use Fisharebest\Webtrees\Http\Middleware\PhpEnvironment; |
34
|
|
|
use Fisharebest\Webtrees\Http\Middleware\ReadConfigIni; |
35
|
|
|
use Fisharebest\Webtrees\Http\Middleware\Router; |
36
|
|
|
use Fisharebest\Webtrees\Http\Middleware\UpdateDatabaseSchema; |
37
|
|
|
use Fisharebest\Webtrees\Http\Middleware\UseCache; |
38
|
|
|
use Fisharebest\Webtrees\Http\Middleware\UseDatabase; |
39
|
|
|
use Fisharebest\Webtrees\Http\Middleware\UseDebugbar; |
40
|
|
|
use Fisharebest\Webtrees\Http\Middleware\UseFilesystem; |
41
|
|
|
use Fisharebest\Webtrees\Http\Middleware\UseLocale; |
42
|
|
|
use Fisharebest\Webtrees\Http\Middleware\UseSession; |
43
|
|
|
use Fisharebest\Webtrees\Http\Middleware\UseTheme; |
44
|
|
|
use Fisharebest\Webtrees\Http\Middleware\UseTransaction; |
45
|
|
|
use Fisharebest\Webtrees\Http\Middleware\BaseUrl; |
46
|
|
|
use Nyholm\Psr7\Factory\Psr17Factory; |
47
|
|
|
use Psr\Http\Message\ResponseFactoryInterface; |
48
|
|
|
use Psr\Http\Message\ServerRequestFactoryInterface; |
49
|
|
|
use Psr\Http\Message\StreamFactoryInterface; |
50
|
|
|
use Psr\Http\Message\UploadedFileFactoryInterface; |
51
|
|
|
use Psr\Http\Message\UriFactoryInterface; |
52
|
|
|
use Throwable; |
53
|
|
|
|
54
|
|
|
use function app; |
55
|
|
|
use function dirname; |
56
|
|
|
use function error_reporting; |
57
|
|
|
use function ob_end_clean; |
58
|
|
|
use function ob_get_level; |
59
|
|
|
use function set_error_handler; |
60
|
|
|
use function set_exception_handler; |
61
|
|
|
use function str_replace; |
62
|
|
|
|
63
|
|
|
use const PHP_EOL; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Definitions for the webtrees application. |
67
|
|
|
*/ |
68
|
|
|
class Webtrees |
69
|
|
|
{ |
70
|
|
|
// The root folder of this installation |
71
|
|
|
public const ROOT_DIR = __DIR__ . '/../'; |
72
|
|
|
|
73
|
|
|
// Some code needs a local filesystem, e.g. for caching. |
74
|
|
|
public const DATA_DIR = self::ROOT_DIR . 'data/'; |
75
|
|
|
|
76
|
|
|
// Location of the file containing the database connection details. |
77
|
|
|
public const CONFIG_FILE = self::ROOT_DIR . 'data/config.ini.php'; |
78
|
|
|
|
79
|
|
|
// Location of the file that triggers maintenance mode. |
80
|
|
|
public const OFFLINE_FILE = self::ROOT_DIR . 'data/offline.txt'; |
81
|
|
|
|
82
|
|
|
// Location of our modules. |
83
|
|
|
public const MODULES_PATH = 'modules_v4/'; |
84
|
|
|
public const MODULES_DIR = self::ROOT_DIR . self::MODULES_PATH; |
85
|
|
|
|
86
|
|
|
// Enable debugging on development builds. |
87
|
|
|
public const DEBUG = self::STABILITY !== ''; |
88
|
|
|
|
89
|
|
|
// We want to know about all PHP errors during development, and fewer in production. |
90
|
|
|
public const ERROR_REPORTING = self::DEBUG ? E_ALL | E_STRICT | E_NOTICE | E_DEPRECATED : E_ALL; |
91
|
|
|
|
92
|
|
|
// The name of the application. |
93
|
|
|
public const NAME = 'webtrees'; |
94
|
|
|
|
95
|
|
|
// Required version of database tables/columns/indexes/etc. |
96
|
|
|
public const SCHEMA_VERSION = 43; |
97
|
|
|
|
98
|
|
|
// e.g. "dev", "alpha", "beta", etc. |
99
|
|
|
public const STABILITY = 'beta.4'; |
100
|
|
|
|
101
|
|
|
// Version number |
102
|
|
|
public const VERSION = '2.0.0' . (self::STABILITY === '' ? '' : '-') . self::STABILITY; |
103
|
|
|
|
104
|
|
|
// Project website. |
105
|
|
|
public const URL = 'https://www.webtrees.net/'; |
106
|
|
|
|
107
|
|
|
private const MIDDLEWARE = [ |
108
|
|
|
PhpEnvironment::class, |
109
|
|
|
EmitResponse::class, |
110
|
|
|
ReadConfigIni::class, |
111
|
|
|
BaseUrl::class, |
112
|
|
|
HandleExceptions::class, |
113
|
|
|
ClientIp::class, |
114
|
|
|
UseDatabase::class, |
115
|
|
|
UseDebugbar::class, |
116
|
|
|
UpdateDatabaseSchema::class, |
117
|
|
|
UseCache::class, |
118
|
|
|
UseFilesystem::class, |
119
|
|
|
UseSession::class, |
120
|
|
|
UseLocale::class, |
121
|
|
|
CheckForMaintenanceMode::class, |
122
|
|
|
UseTheme::class, |
123
|
|
|
DoHousekeeping::class, |
124
|
|
|
CheckCsrf::class, |
125
|
|
|
UseTransaction::class, |
126
|
|
|
LoadRoutes::class, |
127
|
|
|
BootModules::class, |
128
|
|
|
Router::class, |
129
|
|
|
NoRouteFound::class, |
130
|
|
|
]; |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Initialise the application. |
134
|
|
|
* |
135
|
|
|
* @return void |
136
|
|
|
*/ |
137
|
|
|
public function bootstrap(): void |
138
|
|
|
{ |
139
|
|
|
// Show all errors and warnings in development, fewer in production. |
140
|
|
|
error_reporting(self::ERROR_REPORTING); |
141
|
|
|
|
142
|
|
|
set_error_handler($this->phpErrorHandler()); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* An error handler that can be passed to set_error_handler(). |
147
|
|
|
* |
148
|
|
|
* @return Closure |
149
|
|
|
*/ |
150
|
|
|
private function phpErrorHandler(): Closure |
151
|
|
|
{ |
152
|
|
|
return static function (int $errno, string $errstr, string $errfile, int $errline): bool { |
153
|
|
|
// Ignore errors that are silenced with '@' |
154
|
|
|
if (error_reporting() & $errno) { |
155
|
|
|
throw new ErrorException($errstr, 0, $errno, $errfile, $errline); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
return true; |
159
|
|
|
}; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* We can use any PSR-7 / PSR-17 compatible message factory. |
164
|
|
|
* |
165
|
|
|
* @return void |
166
|
|
|
*/ |
167
|
|
|
public function selectMessageFactory(): void |
168
|
|
|
{ |
169
|
|
|
app()->bind(ResponseFactoryInterface::class, Psr17Factory::class); |
170
|
|
|
app()->bind(ServerRequestFactoryInterface::class, Psr17Factory::class); |
171
|
|
|
app()->bind(StreamFactoryInterface::class, Psr17Factory::class); |
172
|
|
|
app()->bind(UploadedFileFactoryInterface::class, Psr17Factory::class); |
173
|
|
|
app()->bind(UriFactoryInterface::class, Psr17Factory::class); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* The webtrees application is built from middleware. |
178
|
|
|
* |
179
|
|
|
* @return string[] |
180
|
|
|
*/ |
181
|
|
|
public function middleware(): array |
182
|
|
|
{ |
183
|
|
|
return self::MIDDLEWARE; |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|