1
1
<?php
2
- /*
3
- * Uguu
4
- *
5
- * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
6
- *
7
- * Note that this was previously distributed under the MIT license 2015-2022.
8
- *
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.
11
- *
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.
14
- *
15
- * This project can be found at <https://github.com/nokonoko/Uguu>.
16
- *
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.
21
- *
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.
26
- *
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/>.
29
- */
30
-
31
- namespace Pomf \Uguu \Classes ;
32
-
33
- use PDO ;
34
-
35
- class Connectorextends Database
2
+ /*
3
+ * Uguu
4
+ *
5
+ * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
6
+ *
7
+ * Note that this was previously distributed under the MIT license 2015-2022.
8
+ *
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.
11
+ *
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.
14
+ *
15
+ * This project can be found at <https://github.com/nokonoko/Uguu>.
16
+ *
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.
21
+ *
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.
26
+ *
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/>.
29
+ */
30
+
31
+ namespace Pomf \Uguu \Classes ;
32
+
33
+ use PDO ;
34
+ use Random \Randomizer ;
35
+
36
+ class Connectorextends Database
37
+ {
38
+ public PDO $ DB ;
39
+ public string $ dbType ;
40
+ public array $ CONFIG ;
41
+ public Response $ response ;
42
+ public Randomizer $ randomizer ;
43
+
44
+ public function errorHandler (int $ errno ,string $ errstr ):void
36
45
{
37
- public PDO $ DB ;
38
- public string $ dbType ;
39
- public array $ CONFIG ;
40
- public Response $ response ;
46
+ if ($ this ->CONFIG ['DEBUG ' ]) {
47
+ $ this ->response ->error (500 ,'Server error: ' .$ errstr );
48
+ }else {
49
+ $ this ->response ->error (500 ,'Server error. ' );
50
+ }
51
+ }
41
52
42
- public function errorHandler (int $ errno ,string $ errstr ):void
43
- {
53
+ public function fatalErrorHandler ():void
54
+ {
55
+ if (!is_null ($ e =error_get_last ())) {
44
56
if ($ this ->CONFIG ['DEBUG ' ]) {
45
- $ this ->response ->error (500 ,'Server error: ' .$ errstr );
57
+ $ this ->response ->error (500 ,'FATAL Server error: ' .print_r ( $ e , true ) );
46
58
}else {
47
59
$ this ->response ->error (500 ,'Server error. ' );
48
60
}
49
61
}
62
+ }
50
63
51
- public function fatalErrorHandler ():void
52
- {
53
- if (!is_null ($ e =error_get_last ())) {
54
- if ($ this ->CONFIG ['DEBUG ' ]) {
55
- $ this ->response ->error (500 ,'FATAL Server error: ' .print_r ($ e ,true ));
56
- }else {
57
- $ this ->response ->error (500 ,'Server error. ' );
58
- }
59
- }
60
- }
61
-
62
- /**
63
- * Reads the config.json file and populates the CONFIG property with the settings
64
- * Also assembles the PDO DB connection and registers error handlers.
65
- *
66
- */
67
- public function __construct ()
68
- {
69
- $ this ->response =new Response ('json ' );
70
- if (!file_exists (__DIR__ .'/../config.json ' )) {
71
- $ this ->response ->error (500 ,'Cant read settings file. ' );
72
- }
73
- $ this ->CONFIG =json_decode (
74
- file_get_contents (__DIR__ .'/../config.json ' ),
75
- true ,
76
- );
77
- ini_set ('display_errors ' ,0 );
78
- set_error_handler ([$ this ,"errorHandler " ]);
79
- register_shutdown_function ([$ this ,"fatalErrorHandler " ]);
80
- $ this ->dbType =$ this ->CONFIG ['DB_MODE ' ];
81
- $ this ->DB =new PDO (
82
- $ this ->CONFIG ['DB_MODE ' ] .': ' .$ this ->CONFIG ['DB_PATH ' ],
83
- $ this ->CONFIG ['DB_USER ' ],
84
- $ this ->CONFIG ['DB_PASS ' ],
85
- );
64
+ /**
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.
67
+ *
68
+ */
69
+ public function __construct ()
70
+ {
71
+ $ this ->response =new Response ('json ' );
72
+ if (!file_exists (__DIR__ .'/../config.json ' )) {
73
+ $ this ->response ->error (500 ,'Cant read settings file. ' );
86
74
}
87
- }
75
+ $ this ->CONFIG =json_decode (
76
+ file_get_contents (__DIR__ .'/../config.json ' ),
77
+ true ,
78
+ );
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 ' ];
83
+ $ this ->DB =new PDO (
84
+ $ this ->CONFIG ['DB_MODE ' ] .': ' .$ this ->CONFIG ['DB_PATH ' ],
85
+ $ this ->CONFIG ['DB_USER ' ],
86
+ $ this ->CONFIG ['DB_PASS ' ],
87
+ );
88
+ $ this ->randomizer =new Randomizer ();
89
+ }
90
+ }