@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @property array $dirs |
19 | 19 | */ |
20 | -class AIDXReader extends PACKReaderAbstract{ |
|
20 | +class AIDXReader extends PACKReaderAbstract { |
|
21 | 21 | |
22 | 22 | /** @var array */ |
23 | 23 | protected $dirs; |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | \fread($this->fh, $this->blocktable[$this->header['RootInfoIndex']]['Size']) |
34 | 34 | ); |
35 | 35 | |
36 | - if($rootInfo['ArchiveType'] !== "\x58\x44\x49\x41"){ // XDIA |
|
36 | + if ($rootInfo['ArchiveType'] !== "\x58\x44\x49\x41") { // XDIA |
|
37 | 37 | throw new WSDBException('invalid AIDX'); |
38 | 38 | } |
39 | 39 | |
@@ -62,12 +62,12 @@ discard block |
||
62 | 62 | $files = \array_fill(0, $n['files'], null); |
63 | 63 | |
64 | 64 | // create a directory object for each dir (4+4 = 8 bytes) |
65 | - foreach($dirs as $i => $_){ |
|
65 | + foreach ($dirs as $i => $_) { |
|
66 | 66 | $dirs[$i] = new ArchiveDirectory(\unpack('LNameOffset/LBlockIndex', \fread($this->fh, 8)), $parent); |
67 | 67 | } |
68 | 68 | |
69 | 69 | // create a file object for each file (4+4+8+8+8+20+4 = 56 bytes) |
70 | - foreach($files as $i => $_){ |
|
70 | + foreach ($files as $i => $_) { |
|
71 | 71 | $files[$i] = new ArchiveFile( |
72 | 72 | \unpack('LNameOffset/LFlags/QFiletime/QSizeUncompressed/QSizeCompressed/a20Hash/x4', \fread($this->fh, 56)), |
73 | 73 | $parent |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | // apply the names to each object in the block |
81 | 81 | $setnames = function(array &$arr) use ($names):void{ |
82 | - foreach($arr ?? [] as $i => $e){ |
|
82 | + foreach ($arr ?? [] as $i => $e) { |
|
83 | 83 | $arr[$i]->Name = \DIRECTORY_SEPARATOR. |
84 | 84 | \substr($names, $e->NameOffset, \strpos($names, "\x00", $e->NameOffset) - $e->NameOffset); |
85 | 85 | } |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | $setnames($files); |
90 | 90 | |
91 | 91 | // loop through the directory stucture recursively and add the block data |
92 | - foreach($dirs as $i => $info){ |
|
93 | - if(isset($this->blocktable[$info->BlockIndex])){ |
|
92 | + foreach ($dirs as $i => $info) { |
|
93 | + if (isset($this->blocktable[$info->BlockIndex])) { |
|
94 | 94 | $dirs[$i]->Content = $this->getBlock($this->blocktable[$info->BlockIndex], $parent.$info->Name); |
95 | 95 | } |
96 | 96 | } |
@@ -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/x8/QRecordSize/QFieldCount/QDescriptionOffset/QRecordCount/QFullRecordSize/QEntryOffset/QNextId/QIDLookupOffset/x8'; |
21 | 21 | |
@@ -28,14 +28,14 @@ discard block |
||
28 | 28 | public function read(string $filename):ReaderInterface{ |
29 | 29 | $this->loadFile($filename); |
30 | 30 | |
31 | - if($this->header['Signature'] !== "\x4c\x42\x54\x44"){ // LBTD |
|
31 | + if ($this->header['Signature'] !== "\x4c\x42\x54\x44") { // LBTD |
|
32 | 32 | throw new WSDBException('invalid DTBL'); |
33 | 33 | } |
34 | 34 | |
35 | 35 | $this->readColumnHeaders(); |
36 | 36 | $this->readData(); |
37 | 37 | |
38 | - if(\count($this->data) !== $this->header['RecordCount']){ |
|
38 | + if (\count($this->data) !== $this->header['RecordCount']) { |
|
39 | 39 | throw new WSDBException('invalid row count'); |
40 | 40 | } |
41 | 41 | |
@@ -54,18 +54,18 @@ discard block |
||
54 | 54 | \fseek($this->fh, $this->header['DescriptionOffset'] + $this->headerSize); |
55 | 55 | |
56 | 56 | // read the column headers (4+4+8+2+2+4 = 24 bytes) |
57 | - for($i = 0; $i < $this->header['FieldCount']; $i++){ |
|
57 | + for ($i = 0; $i < $this->header['FieldCount']; $i++) { |
|
58 | 58 | $this->cols[$i]['header'] = \unpack('LNameLength/x4/QNameOffset/SDataType/x2/x4', \fread($this->fh, 24)); |
59 | 59 | } |
60 | 60 | |
61 | 61 | $offset = $this->header['FieldCount'] * 24 + $this->header['DescriptionOffset'] + $this->headerSize; |
62 | 62 | |
63 | - if($this->header['FieldCount'] % 2){ |
|
63 | + if ($this->header['FieldCount'] % 2) { |
|
64 | 64 | $offset += 8; |
65 | 65 | } |
66 | 66 | |
67 | 67 | // read the column names |
68 | - foreach($this->cols as $i => $col){ |
|
68 | + foreach ($this->cols as $i => $col) { |
|
69 | 69 | \fseek($this->fh, $offset + $col['header']['NameOffset']); |
70 | 70 | |
71 | 71 | // column name (UTF-16LE: length *2) |
@@ -85,21 +85,21 @@ discard block |
||
85 | 85 | $this->data = array_fill(0, $this->header['RecordCount'], null); |
86 | 86 | |
87 | 87 | // read a row |
88 | - foreach($this->data as $i => $_){ |
|
88 | + foreach ($this->data as $i => $_) { |
|
89 | 89 | $data = \fread($this->fh, $this->header['RecordSize']); |
90 | 90 | $row = []; |
91 | 91 | $j = 0; |
92 | 92 | $skip = false; |
93 | 93 | |
94 | 94 | // loop through the columns |
95 | - foreach($this->cols as $c => $col){ |
|
95 | + foreach ($this->cols as $c => $col) { |
|
96 | 96 | |
97 | 97 | // skip 4 bytes if the string offset is 0 (determined by $skip), the current type is string and the next isn't |
98 | - if($skip === true && ($c > 0 && $this->cols[$c - 1]['header']['DataType'] === 130) && $col['header']['DataType'] !== 130){ |
|
98 | + if ($skip === true && ($c > 0 && $this->cols[$c - 1]['header']['DataType'] === 130) && $col['header']['DataType'] !== 130) { |
|
99 | 99 | $j += 4; |
100 | 100 | } |
101 | 101 | |
102 | - switch($col['header']['DataType']){ |
|
102 | + switch ($col['header']['DataType']) { |
|
103 | 103 | case 3: // uint32 |
104 | 104 | case 11: // booleans (stored as uint32 0/1) |
105 | 105 | $v = uint32(\substr($data, $j, 4)); $j += 4; break; |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | // if we run into this, a horrible thing happened |
120 | - if(\count($row) !== $this->header['FieldCount']){ |
|
120 | + if (\count($row) !== $this->header['FieldCount']) { |
|
121 | 121 | throw new WSDBException('invalid field count'); |
122 | 122 | } |
123 | 123 | |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | |
143 | 143 | $v = ''; |
144 | 144 | // loop through the string until we hit 2 nul bytes or the void |
145 | - do{ |
|
145 | + do { |
|
146 | 146 | $s = \fread($this->fh, 2); |
147 | 147 | $v .= $s; |
148 | 148 | } |
149 | - while($s !== "\x00\x00" && $s !== ''); |
|
149 | + while ($s !== "\x00\x00" && $s !== ''); |
|
150 | 150 | |
151 | 151 | \fseek($this->fh, $p); |
152 | 152 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | namespace codemasher\WildstarDB; |
14 | 14 | |
15 | -class AARCReader extends PACKReaderAbstract{ |
|
15 | +class AARCReader extends PACKReaderAbstract { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * @throws \codemasher\WildstarDB\WSDBException |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | \fread($this->fh, $this->blocktable[$this->header['RootInfoIndex']]['Size']) |
26 | 26 | ); |
27 | 27 | |
28 | - if($rootInfo['ArchiveType'] !== "\x43\x52\x41\x41"){ // CRAA |
|
28 | + if ($rootInfo['ArchiveType'] !== "\x43\x52\x41\x41") { // CRAA |
|
29 | 29 | throw new WSDBException('invalid AARC'); |
30 | 30 | } |
31 | 31 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | \fseek($this->fh, $blockInfo['Offset']); |
36 | 36 | |
37 | 37 | // read the data block info (4+20+8 = 32 bytes) |
38 | - for($i = 0; $i < $rootInfo['Blockcount']; $i++){ |
|
38 | + for ($i = 0; $i < $rootInfo['Blockcount']; $i++) { |
|
39 | 39 | $data = unpack('LIndex/a20Hash/QSizeUncompressed', \fread($this->fh, 32)); |
40 | 40 | $hash = \bin2hex($data['Hash']); |
41 | 41 | unset($data['Hash']); |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | namespace codemasher\WildstarDB; |
14 | 14 | |
15 | -class ArchiveDirectory extends ArchiveItemAbstract{ |
|
15 | +class ArchiveDirectory extends ArchiveItemAbstract { |
|
16 | 16 | |
17 | 17 | public $BlockIndex; |
18 | 18 | public $Content; |
@@ -12,15 +12,15 @@ |
||
12 | 12 | |
13 | 13 | namespace codemasher\WildstarDB; |
14 | 14 | |
15 | -abstract class ArchiveItemAbstract{ |
|
15 | +abstract class ArchiveItemAbstract { |
|
16 | 16 | |
17 | 17 | public $Parent; |
18 | 18 | public $Name; |
19 | 19 | public $NameOffset; |
20 | 20 | |
21 | - public function __construct(array $data, string $parent){ |
|
21 | + public function __construct(array $data, string $parent) { |
|
22 | 22 | |
23 | - foreach($data as $property => $value){ |
|
23 | + foreach ($data as $property => $value) { |
|
24 | 24 | $this->{$property} = $value; |
25 | 25 | } |
26 | 26 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @property array $blocktable |
19 | 19 | */ |
20 | -abstract class PACKReaderAbstract extends ReaderAbstract{ |
|
20 | +abstract class PACKReaderAbstract extends ReaderAbstract { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @var string |
@@ -48,14 +48,14 @@ discard block |
||
48 | 48 | $this->loadFile($filename); |
49 | 49 | $this->blocktable = []; |
50 | 50 | |
51 | - if($this->header['Signature'] !== "\x4b\x43\x41\x50"){ // KCAP |
|
51 | + if ($this->header['Signature'] !== "\x4b\x43\x41\x50") { // KCAP |
|
52 | 52 | throw new WSDBException('invalid PACK'); |
53 | 53 | } |
54 | 54 | |
55 | 55 | // read the block info table |
56 | 56 | \fseek($this->fh, $this->header['BlockTableOffset']); |
57 | 57 | |
58 | - for($i = 0; $i < $this->header['BlockCount']; $i++){ |
|
58 | + for ($i = 0; $i < $this->header['BlockCount']; $i++) { |
|
59 | 59 | $this->blocktable[$i] = \unpack('QOffset/QSize', \fread($this->fh, 16)); |
60 | 60 | } |
61 | 61 |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @throws \codemasher\WildstarDB\WSDBException |
77 | 77 | */ |
78 | - public function __construct(LoggerInterface $logger = null){ |
|
78 | + public function __construct(LoggerInterface $logger = null) { |
|
79 | 79 | |
80 | - if(\PHP_INT_SIZE < 8){ |
|
80 | + if (\PHP_INT_SIZE < 8) { |
|
81 | 81 | throw new WSDBException('64-bit PHP required'); |
82 | 82 | } |
83 | 83 | |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | /** |
88 | 88 | * @return void |
89 | 89 | */ |
90 | - public function __destruct(){ |
|
91 | - $this->logger->info('memory usage: '.(\memory_get_usage(true)/1048576).'MB'); |
|
92 | - $this->logger->info('peak memory usage: '.(\memory_get_peak_usage(true)/1048576).'MB'); |
|
90 | + public function __destruct() { |
|
91 | + $this->logger->info('memory usage: '.(\memory_get_usage(true) / 1048576).'MB'); |
|
92 | + $this->logger->info('peak memory usage: '.(\memory_get_peak_usage(true) / 1048576).'MB'); |
|
93 | 93 | |
94 | 94 | $this->close(); |
95 | 95 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function close():ReaderInterface{ |
101 | 101 | |
102 | - if(\is_resource($this->fh)){ |
|
102 | + if (\is_resource($this->fh)) { |
|
103 | 103 | \fclose($this->fh); |
104 | 104 | |
105 | 105 | $this->fh = null; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return mixed|null |
121 | 121 | */ |
122 | - public function __get(string $name){ |
|
122 | + public function __get(string $name) { |
|
123 | 123 | return \property_exists($this, $name) && $name !== 'fh' ? $this->{$name} : null; |
124 | 124 | } |
125 | 125 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | $this->close(); |
134 | 134 | $filename = \realpath($filename); |
135 | 135 | |
136 | - if(!$filename || !\is_file($filename) || !\is_readable($filename)){ |
|
136 | + if (!$filename || !\is_file($filename) || !\is_readable($filename)) { |
|
137 | 137 | throw new WSDBException('input file not readable'); |
138 | 138 | } |
139 | 139 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | |
144 | 144 | $this->logger->info('loading: '.$this->file); |
145 | 145 | |
146 | - if(\strlen($header) !== $this->headerSize){ |
|
146 | + if (\strlen($header) !== $this->headerSize) { |
|
147 | 147 | throw new WSDBException('cannot read header'); |
148 | 148 | } |
149 | 149 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | */ |
166 | 166 | protected function checkData():void{ |
167 | 167 | |
168 | - if(empty($this->data)){ |
|
168 | + if (empty($this->data)) { |
|
169 | 169 | throw new WSDBException('empty data, run ReaderInterface::read() first'); |
170 | 170 | } |
171 | 171 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | */ |
181 | 181 | protected function saveToFile(string $data, string $file):bool{ |
182 | 182 | |
183 | - if(!\is_writable(\dirname($file))){ |
|
183 | + if (!\is_writable(\dirname($file))) { |
|
184 | 184 | throw new WSDBException('cannot write data to file: '.$file.', target directory is not writable'); |
185 | 185 | } |
186 | 186 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | |
201 | 201 | $json = \json_encode($this->data, $jsonOptions); |
202 | 202 | |
203 | - if($file !== null){ |
|
203 | + if ($file !== null) { |
|
204 | 204 | $this->saveToFile($json, $file); |
205 | 205 | } |
206 | 206 | |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | |
223 | 223 | \fputcsv($mh, \array_column($this->cols, 'name'), $delimiter, $enclosure, $escapeChar); |
224 | 224 | |
225 | - foreach($this->data as $row){ |
|
225 | + foreach ($this->data as $row) { |
|
226 | 226 | \fputcsv($mh, \array_values($row), $delimiter, $enclosure, $escapeChar); |
227 | 227 | } |
228 | 228 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | |
233 | 233 | \fclose($mh); |
234 | 234 | |
235 | - if($file !== null){ |
|
235 | + if ($file !== null) { |
|
236 | 236 | $this->saveToFile($csv, $file); |
237 | 237 | } |
238 | 238 | |
@@ -252,10 +252,10 @@ discard block |
||
252 | 252 | $sxe = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><root></root>', \LIBXML_BIGLINES); |
253 | 253 | $types = [3 => 'uint32', 4 => 'float', 11 => 'bool', 20 => 'uint64', 130 => 'string']; |
254 | 254 | |
255 | - foreach($this->data as $row){ |
|
255 | + foreach ($this->data as $row) { |
|
256 | 256 | $item = $sxe->addChild('item'); |
257 | 257 | |
258 | - foreach(\array_values($row) as $i => $value){ |
|
258 | + foreach (\array_values($row) as $i => $value) { |
|
259 | 259 | $item |
260 | 260 | ->addChild($this->cols[$i]['name'], $value) |
261 | 261 | ->addAttribute('dataType', $types[$this->cols[$i]['header']['DataType']]); |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | |
266 | 266 | $xml = $sxe->asXML(); |
267 | 267 | |
268 | - if($file !== null){ |
|
268 | + if ($file !== null) { |
|
269 | 269 | $this->saveToFile($xml, $file); |
270 | 270 | } |
271 | 271 | |
@@ -285,9 +285,9 @@ discard block |
||
285 | 285 | ->ifNotExists() |
286 | 286 | ; |
287 | 287 | |
288 | - foreach($this->cols as $i => $col){ |
|
288 | + foreach ($this->cols as $i => $col) { |
|
289 | 289 | |
290 | - switch($col['header']['DataType']){ |
|
290 | + switch ($col['header']['DataType']) { |
|
291 | 291 | case 3: $createTable->int($col['name'], 10, null, null, 'UNSIGNED'); break; |
292 | 292 | case 4: $createTable->decimal($col['name'], '7,3', 0); break; |
293 | 293 | case 11: $createTable->field($col['name'], 'BOOLEAN'); break; |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | |
302 | 302 | $createTable->query(); |
303 | 303 | |
304 | - if(\count($this->data) < 1){ |
|
304 | + if (\count($this->data) < 1) { |
|
305 | 305 | $this->logger->notice('no records available for table '.$this->name); |
306 | 306 | return $this; |
307 | 307 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @property string $prettyname |
19 | 19 | */ |
20 | -class LTEXReader extends ReaderAbstract{ |
|
20 | +class LTEXReader extends ReaderAbstract { |
|
21 | 21 | |
22 | 22 | // https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c |
23 | 23 | protected const LCID = [ |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | public function read(string $filename):ReaderInterface{ |
44 | 44 | $this->loadFile($filename); |
45 | 45 | |
46 | - if($this->header['Signature'] !== "\x58\x45\x54\x4c"){ // XETL |
|
46 | + if ($this->header['Signature'] !== "\x58\x45\x54\x4c") { // XETL |
|
47 | 47 | throw new WSDBException('invalid LTEX'); |
48 | 48 | } |
49 | 49 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | $this->prettyname = $this->decodeString(\fread($this->fh, $this->header['LongNameStringLength'] * 2)); |
53 | 53 | $this->name = 'LocalizedText_'.$this::LCID[$this->header['LCID']]; |
54 | 54 | $this->cols = [ |
55 | - ['name' => 'ID', 'header' => ['DataType' => 3]], |
|
55 | + ['name' => 'ID', 'header' => ['DataType' => 3]], |
|
56 | 56 | ['name' => 'LocalizedText', 'header' => ['DataType' => 130]], |
57 | 57 | ]; |
58 | 58 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | |
72 | 72 | $this->data = array_fill(0, $this->header['EntryCount'], null); |
73 | 73 | |
74 | - foreach($this->data as $i => $_){ |
|
74 | + foreach ($this->data as $i => $_) { |
|
75 | 75 | // get the id and offset for the data block |
76 | 76 | $c = \unpack('Lid/Loffset', \fread($this->fh, 8)); |
77 | 77 | // save the current position |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | |
83 | 83 | $v = ''; |
84 | 84 | // read until we hit a double nul or the void |
85 | - do{ |
|
85 | + do { |
|
86 | 86 | $s = \fread($this->fh, 2); |
87 | 87 | $v .= $s; |
88 | 88 | } |
89 | - while($s !== "\x00\x00" && $s !== ''); |
|
89 | + while ($s !== "\x00\x00" && $s !== ''); |
|
90 | 90 | |
91 | 91 | $this->data[$i] = ['ID' => $c['id'], 'LocalizedText' => $this->decodeString($v)]; |
92 | 92 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | namespace codemasher\WildstarDB; |
14 | 14 | |
15 | -class ArchiveFile extends ArchiveItemAbstract{ |
|
15 | +class ArchiveFile extends ArchiveItemAbstract { |
|
16 | 16 | |
17 | 17 | public $Flags; |
18 | 18 | public $Filetime; |
@@ -21,11 +21,11 @@ discard block |
||
21 | 21 | public $SizeCompressed; |
22 | 22 | public $Hash; |
23 | 23 | |
24 | - public function __construct(array $data, string $parent){ |
|
24 | + public function __construct(array $data, string $parent) { |
|
25 | 25 | parent::__construct($data, $parent); |
26 | 26 | |
27 | 27 | $this->Hash = \bin2hex($this->Hash); |
28 | - $this->FileUtime = (int)($this->Filetime/100000000); |
|
28 | + $this->FileUtime = (int)($this->Filetime / 100000000); |
|
29 | 29 | # $dt = (new \DateTime)->createFromFormat('U.u', $this->FileUtime) ?: (new \DateTime)->createFromFormat('U', $this->FileUtime); |
30 | 30 | # $this->FileTimeStr = $dt->format(\DateTimeInterface::RFC3339_EXTENDED); |
31 | 31 | } |