]>
jfr.im git - uguu.git/blob - src/Classes/Connector.php
5 * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
7 * Note that this was previously distributed under the MIT license 2015-2022.
9 * If you are a company that wants to use Uguu I urge you to contact me to
10 * solve any potential license issues rather then using pre-2022 code.
12 * A special thanks goes out to the open source community around the world
13 * for supporting and being the backbone of projects like Uguu.
15 * This project can be found at <https://github.com/nokonoko/Uguu>.
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <https://www.gnu.org/licenses/>.
31 namespace Pomf\Uguu\Classes
;
34 use Random\Randomizer
;
36 class Connector
extends Database
39 public string $dbType;
41 public Response
$response;
42 public Randomizer
$randomizer;
44 public function errorHandler(int $errno, string $errstr):void
46 if ($this->CONFIG
['DEBUG']) {
47 $this->response
->error(500, 'Server error: ' . $errstr);
49 $this->response
->error(500, 'Server error.');
53 public function fatalErrorHandler():void
55 if (!is_null($e = error_get_last())) {
56 if ($this->CONFIG
['DEBUG']) {
57 $this->response
->error(500, 'FATAL Server error: ' . print_r($e, true));
59 $this->response
->error(500, 'Server error.');
65 * Reads the config.json file and populates the CONFIG property with the settings
66 * Also assembles the PDO DB connection and registers error handlers.
69 public function __construct()
71 $this->response
= new Response('json');
72 if (!file_exists(__DIR__
. '/../config.json')) {
73 $this->response
->error(500, 'Cant read settings file.');
75 $this->CONFIG
= json_decode(
76 file_get_contents(__DIR__
. '/../config.json'),
79 ini_set('display_errors', 0);
80 set_error_handler([$this, "errorHandler"]);
81 register_shutdown_function([$this, "fatalErrorHandler"]);
82 $this->dbType
= $this->CONFIG
['DB_MODE'];
84 $this->CONFIG
['DB_MODE'] . ':' . $this->CONFIG
['DB_PATH'],
85 $this->CONFIG
['DB_USER'],
86 $this->CONFIG
['DB_PASS'],
88 $this->randomizer
= new Randomizer();