Debian Codegraph @

init.php

raw symbols SCIP
1 <?php
2
3 /**
4 * dmarc-srg - A php parser, viewer and summary report generator for incoming DMARC reports.
5 * Copyright (C) 2020-2025 Aleksey Andreev (liuch)
6 *
7 * Available at:
8 * https://github.com/liuch/dmarc-srg
9 *
10 * This program is free software: you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation, either version 3 of the License.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 if (!defined('ROOT_PATH')) {
24 define('ROOT_PATH', __DIR__ . (__DIR__ === DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR));
25 }
26
27 $vc = require_once(ROOT_PATH . 'config' . DIRECTORY_SEPARATOR . 'vendor_config.php');
28 if (!is_array($vc) || !isset($vc['autoload_file'], $vc['config_file'], $vc['version_suffix'])) {
29 echo 'Error: Incorrect vendor config file';
30 exit;
31 }
32
33 if (defined('PHP_UNIT_TEST')) { /* stop warnings about headers having already been sent */
34 ob_start();
35 }
36
37 define('APP_VERSION', '3.0-pre' . strval($vc['version_suffix']));
38 define('CONFIG_FILE', strval($vc['config_file']));
39
40 $va = strval($vc['autoload_file']);
41 if (is_readable($va)) {
42 require_once($va);
43 }
44
45 spl_autoload_register(function ($class) {
46 $prefix = 'Liuch\\DmarcSrg\\';
47 $prefix_len = 15;
48 $base_dir = ROOT_PATH . 'classes' . DIRECTORY_SEPARATOR;
49
50 if (strncmp($prefix, $class, $prefix_len) === 0) {
51 $relative_class = substr($class, $prefix_len);
52 $file = $base_dir . str_replace('\\', DIRECTORY_SEPARATOR, $relative_class) . '.php';
53 if (file_exists($file)) {
54 require_once($file);
55 }
56 }
57 });
58
59 date_default_timezone_set('GMT');
60
61 $core = new Liuch\DmarcSrg\Core([
62 'auth' => [ 'Liuch\DmarcSrg\Auth' ],
63 'admin' => [ 'Liuch\DmarcSrg\Admin' ],
64 'ehandler' => [ 'Liuch\DmarcSrg\ErrorHandler' ],
65 'config' => [ 'Liuch\DmarcSrg\Config', [ CONFIG_FILE ] ],
66 'status' => [ 'Liuch\DmarcSrg\Status' ],
67 'session' => [ 'Liuch\DmarcSrg\Session' ],
68 'database' => [ 'Liuch\DmarcSrg\Database\DatabaseController' ],
69 'template' => ROOT_PATH . 'template.html'
70 ]);
71 $core->errorHandler()->setLogger(new Liuch\DmarcSrg\Log\PhpSystemLogger());
72
73 set_exception_handler(function ($e) {
74 Liuch\DmarcSrg\Core::instance()->errorHandler()->handleException($e);
75 });
76
77 set_error_handler(function (int $severity, string $message, string $file, int $line) {
78 if (error_reporting() === 0) {
79 return false;
80 }
81 throw new \ErrorException($message, -1, $severity, $file, $line);
82 });
83
84 unset($vc, $va);