@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | namespace codemasher\WildstarDB; |
14 | 14 | |
15 | -class LTEXReader extends ReaderAbstract{ |
|
15 | +class LTEXReader extends ReaderAbstract { |
|
16 | 16 | |
17 | 17 | protected $FORMAT_HEADER = 'a4Signature/LVersion/LLanguage/LLCID/QTagNameStringLength/QTagNameStringPtr/QShortNameStringLength/QShortNameStringPtr/QLongNameStringLength/QLongNameStringPtr/QEntryCount/QEntryIndexPtr/QNameStoreLength/QNameStorePtr'; |
18 | 18 | |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | protected function init():void{ |
24 | 24 | |
25 | - if($this->header['Signature'] !== "\x58\x45\x54\x4c"){ // XETL |
|
25 | + if ($this->header['Signature'] !== "\x58\x45\x54\x4c") { // XETL |
|
26 | 26 | throw new WSDBException('invalid LTEX'); |
27 | 27 | } |
28 | 28 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | $this->name = $this->decodeString(fread($this->fh, $this->header['LongNameStringLength'] * 2)); |
32 | 32 | $this->cols = [ |
33 | - ['name' => 'ID', 'header' => ['DataType' => 3]], |
|
33 | + ['name' => 'ID', 'header' => ['DataType' => 3]], |
|
34 | 34 | ['name' => 'LocalizedText', 'header' => ['DataType' => 130]], |
35 | 35 | ]; |
36 | 36 | |
@@ -48,18 +48,18 @@ discard block |
||
48 | 48 | |
49 | 49 | fseek($this->fh, 0x60 + $this->header['EntryIndexPtr']); |
50 | 50 | |
51 | - for($i = 0; $i < $this->header['EntryCount']; $i++){ |
|
51 | + for ($i = 0; $i < $this->header['EntryCount']; $i++) { |
|
52 | 52 | $a = unpack('Lid/Lpos', fread($this->fh, 8)); |
53 | 53 | $p = ftell($this->fh); |
54 | 54 | $v = ''; |
55 | 55 | |
56 | 56 | fseek($this->fh, 0x60 + $this->header['NameStorePtr'] + ($a['pos'] * 2)); |
57 | 57 | |
58 | - do{ |
|
58 | + do { |
|
59 | 59 | $s = fread($this->fh, 2); |
60 | 60 | $v .= $s; |
61 | 61 | } |
62 | - while($s !== "\x00\x00" && $s !== ''); |
|
62 | + while ($s !== "\x00\x00" && $s !== ''); |
|
63 | 63 | |
64 | 64 | $this->data[$i] = ['ID' => $a['id'], 'LocalizedText' => $this->decodeString($v)]; |
65 | 65 | fseek($this->fh, $p); |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @throws \codemasher\WildstarDB\WSDBException |
70 | 70 | */ |
71 | - public function __construct(LoggerInterface $logger = null){ |
|
71 | + public function __construct(LoggerInterface $logger = null) { |
|
72 | 72 | |
73 | - if(PHP_INT_SIZE < 8){ |
|
73 | + if (PHP_INT_SIZE < 8) { |
|
74 | 74 | throw new WSDBException('64-bit PHP required'); |
75 | 75 | } |
76 | 76 | |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | /** |
81 | 81 | * @return void |
82 | 82 | */ |
83 | - public function __destruct(){ |
|
83 | + public function __destruct() { |
|
84 | 84 | |
85 | - if(is_resource($this->fh)){ |
|
85 | + if (is_resource($this->fh)) { |
|
86 | 86 | fclose($this->fh); |
87 | 87 | } |
88 | 88 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return mixed|null |
95 | 95 | */ |
96 | - public function __get(string $name){ |
|
96 | + public function __get(string $name) { |
|
97 | 97 | return property_exists($this, $name) && $name !== 'fh' ? $this->{$name} : null; |
98 | 98 | } |
99 | 99 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | protected function loadFile(string $filename):void{ |
107 | 107 | |
108 | - if(!is_file($filename) || !is_readable($filename)){ |
|
108 | + if (!is_file($filename) || !is_readable($filename)) { |
|
109 | 109 | throw new WSDBException('input file not readable'); |
110 | 110 | } |
111 | 111 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $this->cols = []; |
119 | 119 | $this->data = []; |
120 | 120 | |
121 | - if(strlen($header) !== 0x60){ |
|
121 | + if (strlen($header) !== 0x60) { |
|
122 | 122 | throw new WSDBException('cannot read header'); |
123 | 123 | } |
124 | 124 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | protected function checkData():void{ |
142 | 142 | |
143 | - if(empty($this->data)){ |
|
143 | + if (empty($this->data)) { |
|
144 | 144 | throw new WSDBException('empty data, run DTBLReader::read() first'); |
145 | 145 | } |
146 | 146 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | */ |
156 | 156 | protected function saveToFile(string $data, string $file):bool{ |
157 | 157 | |
158 | - if(!is_writable(dirname($file))){ |
|
158 | + if (!is_writable(dirname($file))) { |
|
159 | 159 | throw new WSDBException('cannot write data to file: '.$file.', target directory is not writable'); |
160 | 160 | } |
161 | 161 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | |
174 | 174 | $json = json_encode($this->data, $jsonOptions); |
175 | 175 | |
176 | - if($file !== null){ |
|
176 | + if ($file !== null) { |
|
177 | 177 | $this->saveToFile($json, $file); |
178 | 178 | } |
179 | 179 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | |
196 | 196 | fputcsv($mh, array_column($this->cols, 'name'), $delimiter, $enclosure, $escapeChar); |
197 | 197 | |
198 | - foreach($this->data as $row){ |
|
198 | + foreach ($this->data as $row) { |
|
199 | 199 | fputcsv($mh, array_values($row), $delimiter, $enclosure, $escapeChar); |
200 | 200 | } |
201 | 201 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | |
206 | 206 | fclose($mh); |
207 | 207 | |
208 | - if($file !== null){ |
|
208 | + if ($file !== null) { |
|
209 | 209 | $this->saveToFile($csv, $file); |
210 | 210 | } |
211 | 211 | |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | |
227 | 227 | $types = [3 => 'uint32', 4 => 'float', 11 => 'bool', 20 => 'uint64', 130 => 'string']; |
228 | 228 | |
229 | - foreach($this->data as $row){ |
|
229 | + foreach ($this->data as $row) { |
|
230 | 230 | $item = $sxe->addChild('item'); |
231 | 231 | |
232 | - foreach(array_values($row) as $i => $value){ |
|
232 | + foreach (array_values($row) as $i => $value) { |
|
233 | 233 | $item |
234 | 234 | ->addChild($this->cols[$i]['name'], $value) |
235 | 235 | ->addAttribute('dataType', $types[$this->cols[$i]['header']['DataType']]); |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | |
240 | 240 | $xml = $sxe->asXML(); |
241 | 241 | |
242 | - if($file !== null){ |
|
242 | + if ($file !== null) { |
|
243 | 243 | $this->saveToFile($xml, $file); |
244 | 244 | } |
245 | 245 | |
@@ -258,9 +258,9 @@ discard block |
||
258 | 258 | ->ifNotExists() |
259 | 259 | ; |
260 | 260 | |
261 | - foreach($this->cols as $i => $col){ |
|
261 | + foreach ($this->cols as $i => $col) { |
|
262 | 262 | |
263 | - switch($col['header']['DataType']){ |
|
263 | + switch ($col['header']['DataType']) { |
|
264 | 264 | case 3: $createTable->int($col['name'], 10, null, null, 'UNSIGNED'); break; |
265 | 265 | case 4: $createTable->decimal($col['name'], '7,3', 0); break; |
266 | 266 | case 11: $createTable->field($col['name'], 'BOOLEAN'); break; |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | |
273 | 273 | $createTable->query(); |
274 | 274 | |
275 | - if(count($this->data) < 1){ |
|
275 | + if (count($this->data) < 1) { |
|
276 | 276 | $this->logger->notice('no records available for table '.$this->name); |
277 | 277 | return; |
278 | 278 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | namespace codemasher\WildstarDB; |
17 | 17 | |
18 | -class DTBLReader extends ReaderAbstract{ |
|
18 | +class DTBLReader extends ReaderAbstract { |
|
19 | 19 | |
20 | 20 | protected $FORMAT_HEADER = 'a4Signature/LVersion/QTableNameLength/QUnknown1/QRecordSize/QFieldCount/QDescriptionOffset/QRecordCount/QFullRecordSize/QEntryOffset/QNextId/QIDLookupOffset/QUnknown2'; |
21 | 21 | protected $FORMAT_COLUMN = 'LNameLength/LUnknown1/QNameOffset/SDataType/SUnknown2/LUnknown3'; |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | protected function init():void{ |
28 | 28 | |
29 | - if($this->header['Signature'] !== "\x4c\x42\x54\x44"){ // LBTD |
|
29 | + if ($this->header['Signature'] !== "\x4c\x42\x54\x44") { // LBTD |
|
30 | 30 | throw new WSDBException('invalid DTBL'); |
31 | 31 | } |
32 | 32 | |
@@ -36,17 +36,17 @@ discard block |
||
36 | 36 | |
37 | 37 | fseek($this->fh, $this->header['DescriptionOffset'] + 0x60); |
38 | 38 | |
39 | - for($i = 0; $i < $this->header['FieldCount']; $i++){ |
|
39 | + for ($i = 0; $i < $this->header['FieldCount']; $i++) { |
|
40 | 40 | $this->cols[$i]['header'] = unpack($this->FORMAT_COLUMN, fread($this->fh, 0x18)); |
41 | 41 | } |
42 | 42 | |
43 | 43 | $offset = $this->header['FieldCount'] * 0x18 + $this->header['DescriptionOffset'] + 0x60; |
44 | 44 | |
45 | - if($this->header['FieldCount'] % 2){ |
|
45 | + if ($this->header['FieldCount'] % 2) { |
|
46 | 46 | $offset += 8; |
47 | 47 | } |
48 | 48 | |
49 | - foreach($this->cols as $i => $col){ |
|
49 | + foreach ($this->cols as $i => $col) { |
|
50 | 50 | fseek($this->fh, $offset + $col['header']['NameOffset']); |
51 | 51 | |
52 | 52 | $this->cols[$i]['name'] = $this->decodeString(fread($this->fh, $col['header']['NameLength'] * 2)); |
@@ -66,19 +66,19 @@ discard block |
||
66 | 66 | |
67 | 67 | fseek($this->fh, $this->header['EntryOffset'] + 0x60); |
68 | 68 | |
69 | - for($i = 0; $i < $this->header['RecordCount']; $i++){ |
|
69 | + for ($i = 0; $i < $this->header['RecordCount']; $i++) { |
|
70 | 70 | $data = fread($this->fh, $this->header['RecordSize']); |
71 | 71 | $row = []; |
72 | 72 | $j = 0; |
73 | 73 | $skip = false; |
74 | 74 | |
75 | - foreach($this->cols as $c => $col){ |
|
75 | + foreach ($this->cols as $c => $col) { |
|
76 | 76 | |
77 | - if($skip === true && ($c > 0 && $this->cols[$c - 1]['header']['DataType'] === 130) && $col['header']['DataType'] !== 130){ |
|
77 | + if ($skip === true && ($c > 0 && $this->cols[$c - 1]['header']['DataType'] === 130) && $col['header']['DataType'] !== 130) { |
|
78 | 78 | $j += 4; |
79 | 79 | } |
80 | 80 | |
81 | - switch($col['header']['DataType']){ |
|
81 | + switch ($col['header']['DataType']) { |
|
82 | 82 | case 3: // uint32 |
83 | 83 | case 11: // booleans (stored as uint32 0/1) |
84 | 84 | $v = unpack('L', substr($data, $j, 4))[1]; $j += 4; break; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $row[$col['name']] = $v; |
96 | 96 | } |
97 | 97 | |
98 | - if(count($row) !== $this->header['FieldCount']){ |
|
98 | + if (count($row) !== $this->header['FieldCount']) { |
|
99 | 99 | throw new WSDBException('invalid field count'); |
100 | 100 | } |
101 | 101 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | |
105 | 105 | fclose($this->fh); |
106 | 106 | |
107 | - if(count($this->data) !== $this->header['RecordCount']){ |
|
107 | + if (count($this->data) !== $this->header['RecordCount']) { |
|
108 | 108 | throw new WSDBException('invalid row count'); |
109 | 109 | } |
110 | 110 | |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | |
128 | 128 | $v = ''; |
129 | 129 | |
130 | - do{ |
|
130 | + do { |
|
131 | 131 | $s = fread($this->fh, 2); |
132 | 132 | $v .= $s; |
133 | 133 | } |
134 | - while($s !== "\x00\x00" && $s !== ''); |
|
134 | + while ($s !== "\x00\x00" && $s !== ''); |
|
135 | 135 | |
136 | 136 | fseek($this->fh, $p); |
137 | 137 |
@@ -14,7 +14,7 @@ |
||
14 | 14 | |
15 | 15 | use chillerlan\Database\Database; |
16 | 16 | |
17 | -interface ReaderInterface{ |
|
17 | +interface ReaderInterface { |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @param string $name |