1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * webtrees: online genealogy |
||
4 | * Copyright (C) 2018 webtrees development team |
||
5 | * This program is free software: you can redistribute it and/or modify |
||
6 | * it under the terms of the GNU General Public License as published by |
||
7 | * the Free Software Foundation, either version 3 of the License, or |
||
8 | * (at your option) any later version. |
||
9 | * This program is distributed in the hope that it will be useful, |
||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
12 | * GNU General Public License for more details. |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
15 | */ |
||
16 | namespace Fisharebest\Webtrees; |
||
17 | |||
18 | use ErrorException; |
||
19 | use Fisharebest\Webtrees\Http\Controllers\SetupController; |
||
20 | use Symfony\Component\HttpFoundation\RedirectResponse; |
||
21 | use Symfony\Component\HttpFoundation\Request; |
||
22 | |||
23 | // This script (uniquely) does not load session.php. |
||
24 | // session.php won’t run until a configuration file exists… |
||
25 | // This next block of code is a minimal version of session.php |
||
26 | error_reporting(E_ALL); |
||
27 | |||
28 | define('WT_CONFIG_FILE', 'config.ini.php'); |
||
29 | |||
30 | require 'vendor/autoload.php'; |
||
31 | |||
32 | define('WT_WEBTREES', 'webtrees'); |
||
33 | define('WT_BASE_URL', ''); |
||
34 | define('WT_DATA_DIR', 'data/'); |
||
35 | define('WT_REQUIRED_MYSQL_VERSION', '5.0.13'); |
||
36 | define('WT_REQUIRED_PHP_VERSION', '5.6'); |
||
37 | define('WT_MODULES_DIR', 'modules_v3/'); |
||
38 | define('WT_ROOT', ''); |
||
39 | |||
40 | // PHP requires a time zone to be set. We'll set a better one later on. |
||
41 | date_default_timezone_set('UTC'); |
||
42 | |||
43 | // Convert PHP errors into exceptions |
||
44 | set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
||
45 | throw new ErrorException($errstr, 0, $errno, $errfile, $errline); |
||
46 | }); |
||
47 | |||
48 | define('WT_LOCALE', I18N::init('en-US')); |
||
49 | |||
50 | // The HTTP request. |
||
51 | $request = Request::createFromGlobals(); |
||
52 | $method = $request->getMethod(); |
||
53 | $route = $request->get('route'); |
||
54 | |||
55 | switch ($method . ':' . $route) { |
||
56 | default: |
||
57 | $url = Html::url('setup.php', ['route' => 'setup']); |
||
58 | $response = new RedirectResponse($url); |
||
59 | break; |
||
60 | |||
61 | case 'GET:setup': |
||
62 | case 'POST:setup': |
||
63 | $response = (new SetupController)->setup($request); |
||
64 | break; |
||
65 | } |
||
66 | |||
67 | $response->prepare($request)->send(); |
||
68 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.