@@ -12,4 +12,4 @@ |
||
| 12 | 12 | |
| 13 | 13 | namespace codemasher\WildstarDB; |
| 14 | 14 | |
| 15 | -class WSDBException extends \Exception{} |
|
| 15 | +class WSDBException extends \Exception {} |
|
@@ -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 | } |
@@ -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 |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | namespace codemasher\WildstarDB; |
| 16 | 16 | |
| 17 | -class LTEXReader extends ReaderAbstract{ |
|
| 17 | +class LTEXReader extends ReaderAbstract { |
|
| 18 | 18 | |
| 19 | 19 | protected $FORMAT_HEADER = 'a4Signature/LVersion/LLanguage/LLCID/QTagNameStringLength/QTagNameStringPtr/QShortNameStringLength/QShortNameStringPtr/QLongNameStringLength/QLongNameStringPtr/QEntryCount/QEntryIndexPtr/QNameStoreLength/QNameStorePtr'; |
| 20 | 20 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | protected function init():void{ |
| 26 | 26 | |
| 27 | - if($this->header['Signature'] !== "\x58\x45\x54\x4c"){ // XETL |
|
| 27 | + if ($this->header['Signature'] !== "\x58\x45\x54\x4c") { // XETL |
|
| 28 | 28 | throw new WSDBException('invalid LTEX'); |
| 29 | 29 | } |
| 30 | 30 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | $this->name = $this->decodeString(fread($this->fh, $this->header['LongNameStringLength'] * 2)); |
| 34 | 34 | $this->cols = [ |
| 35 | - ['name' => 'ID', 'header' => ['DataType' => 3]], |
|
| 35 | + ['name' => 'ID', 'header' => ['DataType' => 3]], |
|
| 36 | 36 | ['name' => 'LocalizedText', 'header' => ['DataType' => 130]], |
| 37 | 37 | ]; |
| 38 | 38 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | fseek($this->fh, 0x60 + $this->header['EntryIndexPtr']); |
| 52 | 52 | |
| 53 | - for($i = 0; $i < $this->header['EntryCount']; $i++){ |
|
| 53 | + for ($i = 0; $i < $this->header['EntryCount']; $i++) { |
|
| 54 | 54 | $id = uint32(fread($this->fh, 4)); |
| 55 | 55 | $pos = uint32(fread($this->fh, 4)); |
| 56 | 56 | $p = ftell($this->fh); |
@@ -58,11 +58,11 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | fseek($this->fh, 0x60 + $this->header['NameStorePtr'] + ($pos * 2)); |
| 60 | 60 | |
| 61 | - do{ |
|
| 61 | + do { |
|
| 62 | 62 | $s = fread($this->fh, 2); |
| 63 | 63 | $v .= $s; |
| 64 | 64 | } |
| 65 | - while($s !== "\x00\x00" && $s !== ''); |
|
| 65 | + while ($s !== "\x00\x00" && $s !== ''); |
|
| 66 | 66 | |
| 67 | 67 | $this->data[$i] = ['ID' => $id, 'LocalizedText' => $this->decodeString($v)]; |
| 68 | 68 | fseek($this->fh, $p); |
@@ -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 = uint32(substr($data, $j, 4)); $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 | |
@@ -9,6 +9,6 @@ |
||
| 9 | 9 | |
| 10 | 10 | namespace codemasher\WildstarDB; |
| 11 | 11 | |
| 12 | -if(!defined('WSDB_FUNCTIONS')){ |
|
| 12 | +if (!defined('WSDB_FUNCTIONS')) { |
|
| 13 | 13 | require_once __DIR__.'/functions.php'; |
| 14 | 14 | } |
@@ -13,15 +13,15 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | // http://php.net/manual/en/function.pack.php#119402 |
| 15 | 15 | |
| 16 | -function uint32($i, bool $endianness = null){ |
|
| 16 | +function uint32($i, bool $endianness = null) { |
|
| 17 | 17 | |
| 18 | - if($endianness === true){ // big-endian |
|
| 18 | + if ($endianness === true) { // big-endian |
|
| 19 | 19 | $f = 'N'; |
| 20 | 20 | } |
| 21 | - elseif($endianness === false){ // little-endian |
|
| 21 | + elseif ($endianness === false) { // little-endian |
|
| 22 | 22 | $f = 'V'; |
| 23 | 23 | } |
| 24 | - else{ // machine byte order |
|
| 24 | + else { // machine byte order |
|
| 25 | 25 | $f = 'L'; |
| 26 | 26 | } |
| 27 | 27 | |
@@ -30,15 +30,15 @@ discard block |
||
| 30 | 30 | return is_array($i) ? $i[1] : $i; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | -function uint64($i, bool $endianness = null){ |
|
| 33 | +function uint64($i, bool $endianness = null) { |
|
| 34 | 34 | |
| 35 | - if($endianness === true){ // big-endian |
|
| 35 | + if ($endianness === true) { // big-endian |
|
| 36 | 36 | $f = 'J'; |
| 37 | 37 | } |
| 38 | - elseif($endianness === false){ // little-endian |
|
| 38 | + elseif ($endianness === false) { // little-endian |
|
| 39 | 39 | $f = 'P'; |
| 40 | 40 | } |
| 41 | - else{ // machine byte order |
|
| 41 | + else { // machine byte order |
|
| 42 | 42 | $f = 'Q'; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -47,15 +47,15 @@ discard block |
||
| 47 | 47 | return is_array($i) ? $i[1] : $i; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | -function float($i, bool $endianness = null){ |
|
| 50 | +function float($i, bool $endianness = null) { |
|
| 51 | 51 | |
| 52 | - if($endianness === true){ // big-endian |
|
| 52 | + if ($endianness === true) { // big-endian |
|
| 53 | 53 | $f = 'G'; |
| 54 | 54 | } |
| 55 | - elseif($endianness === false){ // little-endian |
|
| 55 | + elseif ($endianness === false) { // little-endian |
|
| 56 | 56 | $f = 'g'; |
| 57 | 57 | } |
| 58 | - else{ // machine byte order |
|
| 58 | + else { // machine byte order |
|
| 59 | 59 | $f = 'f'; |
| 60 | 60 | } |
| 61 | 61 | |