8
8
9
9
namespace VectorNetworkProject \TheMix \provider ;
10
10
11
-
12
11
use pocketmine \utils \Config ;
13
12
use pocketmine \utils \MainLogger ;
14
13
use VectorNetworkProject \TheMix \lib \database \Provider ;
@@ -23,38 +22,42 @@ class JSON extends Provider
23
22
24
23
/**
25
24
* JSON constructor.
25
+ *
26
26
* @param string $xuid
27
27
* @param string $file
28
28
*/
29
29
public function __construct (string $ xuid , string $ file )
30
30
{
31
- $ this ->path = self ::getPath ('datas ' , 'json ' ) . $ xuid . '/ ' ;
32
- $ this ->file = $ file . '.json ' ;
31
+ $ this ->path = self ::getPath ('datas ' , 'json ' ). $ xuid. '/ ' ;
32
+ $ this ->file = $ file. '.json ' ;
33
33
}
34
34
35
35
public function init (array $ data = []): void
36
36
{
37
- if (!$ this ->hasTable ()) $ this ->createTable ($ data );
37
+ if (!$ this ->hasTable ()) {
38
+ $ this ->createTable ($ data );
39
+ }
38
40
}
39
41
40
42
/**
41
43
* @param array $table
44
+ *
42
45
* @return void
43
46
*/
44
47
public function createTable (array $ table = []): void
45
48
{
46
49
@mkdir ($ this ->path , 0755 , true );
47
- $ config = new Config ($ this ->path . $ this ->file , Config::JSON , $ table );
50
+ $ config = new Config ($ this ->path . $ this ->file , Config::JSON , $ table );
48
51
$ config ->save ();
49
- MainLogger::getLogger ()->debug (" [PROVIDER] Create " .$ this ->file );
52
+ MainLogger::getLogger ()->debug (' [PROVIDER] Create ' .$ this ->file );
50
53
}
51
54
52
55
/**
53
56
* @return bool
54
57
*/
55
58
public function hasTable (): bool
56
59
{
57
- return file_exists ($ this ->path . $ this ->file )
60
+ return file_exists ($ this ->path . $ this ->file )
58
61
? true
59
62
: false ;
60
63
}
@@ -64,27 +67,29 @@ public function hasTable(): bool
64
67
*/
65
68
public function deleteTable (): void
66
69
{
67
- unlink ($ this ->path . $ this ->file );
70
+ unlink ($ this ->path . $ this ->file );
68
71
}
69
72
70
73
/**
71
- * @param string $key
74
+ * @param string $key
72
75
* @param bool|mixed $data
73
76
*/
74
77
public function set (string $ key , $ data ): void
75
78
{
76
- $ config = new Config ($ this ->path . $ this ->file , Config::JSON );
79
+ $ config = new Config ($ this ->path . $ this ->file , Config::JSON );
77
80
$ config ->set ($ key , $ data );
78
81
$ config ->save ();
79
82
}
80
83
81
84
/**
82
85
* @param string $key
86
+ *
83
87
* @return bool|mixed
84
88
*/
85
89
public function get (string $ key )
86
90
{
87
- $ config = new Config ($ this ->path . $ this ->file , Config::JSON );
91
+ $ config = new Config ($ this ->path .$ this ->file , Config::JSON );
92
+
88
93
return $ config ->get ($ key );
89
94
}
90
95
@@ -93,7 +98,8 @@ public function get(string $key)
93
98
*/
94
99
public function getAll (): array
95
100
{
96
- $ config = new Config ($ this ->path . $ this ->file , Config::JSON );
101
+ $ config = new Config ($ this ->path .$ this ->file , Config::JSON );
102
+
97
103
return $ config ->getAll ();
98
104
}
99
105
@@ -102,29 +108,33 @@ public function getAll(): array
102
108
*/
103
109
public function getKeys (): array
104
110
{
105
- $ config = new Config ($ this ->path . $ this ->file , Config::JSON );
111
+ $ config = new Config ($ this ->path .$ this ->file , Config::JSON );
112
+
106
113
return $ config ->getAll (true );
107
114
}
108
115
109
116
/**
110
117
* @param string $key
118
+ *
111
119
* @return bool
112
120
*/
113
121
public function exists (string $ key ): bool
114
122
{
115
- $ config = new Config ($ this ->path . $ this ->file , Config::JSON );
123
+ $ config = new Config ($ this ->path .$ this ->file , Config::JSON );
124
+
116
125
return $ config ->exists ($ key )
117
126
? true
118
127
: false ;
119
128
}
120
129
121
130
/**
122
131
* @param string $key
132
+ *
123
133
* @return void
124
134
*/
125
135
public function remove (string $ key ): void
126
136
{
127
- $ config = new Config ($ this ->path . $ this ->file , Config::JSON );
137
+ $ config = new Config ($ this ->path . $ this ->file , Config::JSON );
128
138
$ config ->remove ($ key );
129
139
}
130
140
}
0 commit comments