Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"type": "yii2-extension",
"require": {
"php": ">=5.4.0",
"php": ">=7.4.0",
"yiisoft/yii2": "*"
},
"autoload": {
Expand Down
38 changes: 33 additions & 5 deletions vendor/SxGeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,36 @@ class SxGeo {

public $batch_mode = false;
public $memory_mode = false;
/**
* @var mixed
*/
private $b_idx_len;
/**
* @var mixed
*/
private $id_len;
/**
* @var int|mixed
*/
private $block_len;
/**
* @var mixed
*/
private $max_region;
/**
* @var mixed
*/
private $max_city;
/**
* @var mixed
*/
private $max_country;
/**
* @var false|string|string[]
*/
private $pack;

public function __construct($db_file = 'SxGeo.dat', $type = self::SXGEO_FILE){
public function __construct($db_file = 'SxGeo.dat', $type = self::SXGEO_FILE){
$this->fh = fopen($db_file, 'rb');
// Сначала убеждаемся, что есть файл базы данных
$header = fread($this->fh, 40); // В версии 2.2 заголовок увеличился на 8 байт
Expand Down Expand Up @@ -219,7 +247,7 @@ protected function unpack($pack, $item = ''){
$pos = 0;
foreach($pack AS $p){
list($type, $name) = explode(':', $p);
$type0 = $type{0};
$type0 = $type[0];
if($empty) {
$unpacked[$name] = $type0 == 'b' || $type0 == 'c' ? '' : 0;
continue;
Expand All @@ -243,15 +271,15 @@ protected function unpack($pack, $item = ''){
case 'T': $v = unpack('C', $val); break;
case 's': $v = unpack('s', $val); break;
case 'S': $v = unpack('S', $val); break;
case 'm': $v = unpack('l', $val . (ord($val{2}) >> 7 ? "\xff" : "\0")); break;
case 'm': $v = unpack('l', $val . (ord($val[2]) >> 7 ? "\xff" : "\0")); break;
case 'M': $v = unpack('L', $val . "\0"); break;
case 'i': $v = unpack('l', $val); break;
case 'I': $v = unpack('L', $val); break;
case 'f': $v = unpack('f', $val); break;
case 'd': $v = unpack('d', $val); break;

case 'n': $v = current(unpack('s', $val)) / pow(10, $type{1}); break;
case 'N': $v = current(unpack('l', $val)) / pow(10, $type{1}); break;
case 'n': $v = current(unpack('s', $val)) / pow(10, $type[1]); break;
case 'N': $v = current(unpack('l', $val)) / pow(10, $type[1]); break;

case 'c': $v = rtrim($val, ' '); break;
case 'b': $v = $val; $l++; break;
Expand Down