Skip to content

Commit 418625f

Browse files
committed
fix issue #125
1 parent 6ca015c commit 418625f

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"ext-json": "*",
1818
"ext-sockets": "*",
1919
"doctrine/collections": "^2.1",
20-
"doctrine/dbal": "^3.8",
20+
"doctrine/dbal": "^4.0",
2121
"psr/log": "^3.0",
2222
"psr/simple-cache": "^3.0",
2323
"symfony/event-dispatcher": "^6.0|^7.0"
@@ -26,7 +26,7 @@
2626
"kubawerlos/php-cs-fixer-custom-fixers": "^3.19",
2727
"monolog/monolog": "^3.5",
2828
"phpstan/phpstan": "^1.10",
29-
"phpunit/phpunit": "^10.5",
29+
"phpunit/phpunit": "^11.0",
3030
"symplify/easy-coding-standard": "^12.1"
3131
},
3232
"license": "MIT",

src/MySQLReplication/BinaryDataReader/BinaryDataReader.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,21 @@ public function readUInt24(): int
114114
return $data[1] + ($data[2] << 8) + ($data[3] << 16);
115115
}
116116

117-
public function readUInt64(): string
117+
public function readUInt64(): string|int
118118
{
119119
return $this->unpackUInt64($this->read(self::UNSIGNED_INT64_LENGTH));
120120
}
121121

122-
public function unpackUInt64(string $binary): string
122+
public function unpackUInt64(string $binary): string|int
123123
{
124124
$data = self::unpack('V*', $binary);
125125

126-
return bcadd((string)$data[1], bcmul((string)$data[2], bcpow('2', '32')));
126+
$num = bcadd((string)$data[1], bcmul((string)$data[2], bcpow('2', '32')));
127+
if($num>PHP_INT_MAX || $num<PHP_INT_MIN){
128+
return $num;
129+
}else{
130+
return intval($num);
131+
}
127132
}
128133

129134
public function readInt24(): int
@@ -138,11 +143,16 @@ public function readInt24(): int
138143
return $res;
139144
}
140145

141-
public function readInt64(): string
146+
public function readInt64(): string|int
142147
{
143148
$data = self::unpack('V*', $this->read(self::UNSIGNED_INT64_LENGTH));
144149

145-
return bcadd((string)$data[1], (string)($data[2] << 32));
150+
$num = bcadd((string)$data[1], (string)($data[2] << 32));
151+
if($num>PHP_INT_MAX || $num<PHP_INT_MIN){
152+
return $num;
153+
}else{
154+
return intval($num);
155+
}
146156
}
147157

148158
public function readLengthString(int $size): string
@@ -286,7 +296,7 @@ public function readDouble(): float
286296

287297
public function readTableId(): string
288298
{
289-
return $this->unpackUInt64($this->read(self::UNSIGNED_INT48_LENGTH) . chr(0) . chr(0));
299+
return (string)$this->unpackUInt64($this->read(self::UNSIGNED_INT48_LENGTH) . chr(0) . chr(0));
290300
}
291301

292302
public function isComplete(int $size): bool

src/MySQLReplication/Event/RotateEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class RotateEvent extends EventCommon
1313
{
1414
public function makeRotateEventDTO(): RotateDTO
1515
{
16-
$binFilePos = $this->binaryDataReader->readUInt64();
16+
$binFilePos = (string)$this->binaryDataReader->readUInt64();
1717
$binFileName = $this->binaryDataReader->read(
1818
$this->eventInfo->getSizeNoHeader() - $this->getSizeToRemoveByVersion()
1919
);

src/MySQLReplication/Event/RowEvent/RowEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ public function makeUpdateRowsDTO(): ?UpdateRowsDTO
416416

417417
protected function findTableMap(): ?TableMap
418418
{
419-
$tableId = $this->binaryDataReader->readTableId();
419+
$tableId = (string)$this->binaryDataReader->readTableId();
420420
$this->binaryDataReader->advance(2);
421421

422422
if (in_array(

src/MySQLReplication/Event/XidEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ class XidEvent extends EventCommon
1313
{
1414
public function makeXidDTO(): XidDTO
1515
{
16-
return new XidDTO($this->eventInfo, $this->binaryDataReader->readUInt64());
16+
return new XidDTO($this->eventInfo, (string)$this->binaryDataReader->readUInt64());
1717
}
1818
}

0 commit comments

Comments
 (0)