|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BPT\database; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* |
|
7
|
|
|
*/ |
|
8
|
|
|
class handler { |
|
9
|
|
|
/** |
|
10
|
|
|
* @const types database |
|
11
|
|
|
*/ |
|
12
|
|
|
const TYPES = ['Mysqli', 'Medoo', 'Json']; |
|
13
|
|
|
/** |
|
14
|
|
|
* @const Medoo database types |
|
15
|
|
|
*/ |
|
16
|
|
|
const Medoo_Types = ['mysql', 'mariadb', 'pgsql', 'sybase', 'oracle', 'mssql', 'sqlite']; |
|
17
|
|
|
/** |
|
18
|
|
|
* @var type database |
|
|
|
|
|
|
19
|
|
|
*/ |
|
20
|
|
|
public static $type; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var host for database |
|
|
|
|
|
|
23
|
|
|
* Default value localhost |
|
24
|
|
|
*/ |
|
25
|
|
|
public static $host; |
|
26
|
|
|
/** |
|
27
|
|
|
* @var username database username |
|
|
|
|
|
|
28
|
|
|
*/ |
|
29
|
|
|
public static $username; |
|
30
|
|
|
/** |
|
31
|
|
|
* @var dbname database name |
|
|
|
|
|
|
32
|
|
|
*/ |
|
33
|
|
|
public static $dbname; |
|
34
|
|
|
/** |
|
35
|
|
|
* @var charset database |
|
|
|
|
|
|
36
|
|
|
*/ |
|
37
|
|
|
public static $charset; |
|
38
|
|
|
/** |
|
39
|
|
|
* @var password database password |
|
|
|
|
|
|
40
|
|
|
*/ |
|
41
|
|
|
public static $password; |
|
42
|
|
|
/** |
|
43
|
|
|
* @var connection database |
|
|
|
|
|
|
44
|
|
|
*/ |
|
45
|
|
|
public static $connect; |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct (array $settings) { |
|
52
|
|
|
if (in_array($settings['type'], self::TYPES)) { |
|
53
|
|
|
if ($settings['type'] === 'Mysqli') { |
|
54
|
|
|
if (self::CheckParam($settings)) { |
|
55
|
|
|
$db = new \Mysqlidb([ |
|
|
|
|
|
|
56
|
|
|
'host' => self::$host, |
|
57
|
|
|
'username' => self::$username, |
|
58
|
|
|
'password' => self::$password, |
|
59
|
|
|
'db' => self::$dbname, |
|
60
|
|
|
'charset' => self::$charset |
|
61
|
|
|
]); |
|
62
|
|
|
if ($db) { |
|
|
|
|
|
|
63
|
|
|
self::$connect = $db; |
|
64
|
|
|
print_r($db); |
|
65
|
|
|
} |
|
66
|
|
|
else { |
|
67
|
|
|
print self::$username; |
|
68
|
|
|
throw new \exception('a problem to connecting'); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
else { |
|
72
|
|
|
throw new \exception('required parameters not found'); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
if ($settings['type'] === 'Json') { |
|
76
|
|
|
if (isset($settings['dbname'])) { |
|
77
|
|
|
self::$type = $settings['type']; |
|
78
|
|
|
self::$dbname = $settings['dbname']; |
|
79
|
|
|
(new database())->json_init(); |
|
80
|
|
|
} |
|
81
|
|
|
else { |
|
82
|
|
|
throw new \exception('parameter dbanme not found'); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
else { |
|
87
|
|
|
throw new \exception('parameter type not found'); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
private static function CheckParam (array $array) { |
|
92
|
|
|
if (isset($array['username']) && isset($array['dbname']) && isset($array['password'])) { |
|
93
|
|
|
self::$host = $array['host'] ?? 'localhost'; |
|
|
|
|
|
|
94
|
|
|
self::$username = $array['username']; |
|
95
|
|
|
self::$dbname = $array['dbname']; |
|
96
|
|
|
self::$password = $array['password']; |
|
97
|
|
|
self::$charset = $array['charset'] ?? 'utf8'; |
|
|
|
|
|
|
98
|
|
|
return true; |
|
99
|
|
|
} |
|
100
|
|
|
else { |
|
101
|
|
|
return false; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths