xref: /webtrees/app/Webtrees.php (revision 9b802b22a7b94d1d30e0433dd46fe641f3757505)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 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 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees;
19
20use ErrorException;
21use function date_default_timezone_set;
22use function error_reporting;
23use function set_error_handler;
24
25/**
26 * Definitions for the webtrees application.
27 */
28class Webtrees
29{
30    // Location of the file containing the database connection details.
31    public const CONFIG_FILE = __DIR__ . '/../data/config.ini.php';
32
33    // Enable debugging on development builds.
34    public const DEBUG = self::STABILITY !== '';
35
36    // We want to know about all PHP errors during development, and fewer in production.
37    public const ERROR_REPORTING = self::DEBUG ? E_ALL | E_STRICT | E_NOTICE | E_DEPRECATED : E_ALL;
38
39    // The name of the application.
40    public const NAME = 'webtrees';
41
42    // Required version of database tables/columns/indexes/etc.
43    public const SCHEMA_VERSION = 41;
44
45    // e.g. "dev", "alpha", "beta.3", etc.
46    public const STABILITY = 'dev';
47
48    // Project website.
49    public const URL = 'https://www.webtrees.net/';
50
51    // Version number
52    public const VERSION = '2.0.0' . (self::STABILITY === '' ? '' : '-') . self::STABILITY;
53
54    // Location of our modules and themes. These are used as URLs and folder paths.
55    public const MODULES_PATH = 'modules_v3/';
56
57    // Location of themes (core and custom).
58    public const THEMES_PATH = 'themes/';
59
60    // Location of CSS/JS/etc. assets. See also webpack.mix.js.
61    public const ASSETS_PATH = 'public/assets-2.0.0/';
62
63    // Location of our installation of CK editor.
64    public const CKEDITOR_PATH = 'public/ckeditor-4.5.2-custom/';
65
66    /**
67     * Initialise the application.
68     *
69     * @return void
70     */
71    public static function init()
72    {
73        // Show all errors and warnings in development, fewer in production.
74        error_reporting(self::ERROR_REPORTING);
75
76        // PHP requires a time zone to be set. We'll set a better one later on.
77        date_default_timezone_set('UTC');
78
79        // Convert PHP warnings/notices into exceptions
80        set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline): bool {
81            // Ignore errors that are silenced with '@'
82            if (error_reporting() & $errno) {
83                throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
84            }
85
86            return true;
87        });
88    }
89}
90