]> jfr.im git - uguu.git/blame - src/Classes/Connector.php
add padding
[uguu.git] / src / Classes / Connector.php
CommitLineData
e480c0e5
GJ
1<?php
2
3/**
4 * Uguu
5 *
6 * @copyright Copyright (c) 2022 Go Johansson (nokonoko) <neku@pomf.se>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22namespace Pomf\Uguu\Classes;
23
24use Exception;
25use PDO;
26
27class Connector extends Database
28{
29 public PDO $DB;
30 public array $CONFIG;
31
32 /**
33 * @throws Exception
34 */
35 public function __construct()
36 {
37 if (!file_exists(__DIR__ . '/../config.json')) {
38 throw new Exception('Cant read settings file.', 500);
39 }
40 try {
41 $this->CONFIG = json_decode(
42 file_get_contents(__DIR__ . '/../config.json'),
43 true
44 );
45 $this->assemble();
46 } catch (Exception) {
47 throw new Exception('Cant populate settings.', 500);
48 }
49 }
50
51 /**
52 * @throws Exception
53 */
54 public function assemble()
55 {
56 try {
57 $this->DB = new PDO(
58 $this->CONFIG['DB_MODE'] . ':' . $this->CONFIG['DB_PATH'],
59 $this->CONFIG['DB_USER'],
60 $this->CONFIG['DB_PASS']
61 );
62 } catch (Exception) {
63 throw new Exception('Cant connect to DB.', 500);
64 }
65 }
66}