Skip to content

Commit 556ef15

Browse files
committed
remove bcmath dependency, fallback to BigInteger if neccessary
1 parent bde92bc commit 556ef15

File tree

11 files changed

+263
-209
lines changed

11 files changed

+263
-209
lines changed

PhpAmqpLib/Channel/AMQPChannel.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,14 +866,15 @@ protected function internal_ack_handler($delivery_tag, $multiple, $handler)
866866
*/
867867
protected function get_keys_less_or_equal(array $messages, $value)
868868
{
869+
$value = (int) $value;
869870
$keys = array_reduce(
870871
array_keys($messages),
871872

872873
/**
873874
* @param string $key
874875
*/
875876
function ($keys, $key) use ($value) {
876-
if (bccomp($key, $value, 0) <= 0) {
877+
if ($key <= $value) {
877878
$keys[] = $key;
878879
}
879880

@@ -1181,7 +1182,7 @@ public function basic_publish(
11811182

11821183
if ($this->next_delivery_tag > 0) {
11831184
$this->published_messages[$this->next_delivery_tag] = $msg;
1184-
$this->next_delivery_tag = bcadd($this->next_delivery_tag, '1', 0);
1185+
$this->next_delivery_tag++;
11851186
}
11861187
}
11871188

@@ -1241,7 +1242,7 @@ public function publish_batch()
12411242

12421243
if ($this->next_delivery_tag > 0) {
12431244
$this->published_messages[$this->next_delivery_tag] = $msg;
1244-
$this->next_delivery_tag = bcadd($this->next_delivery_tag, '1', 0);
1245+
$this->next_delivery_tag++;
12451246
}
12461247
}
12471248

PhpAmqpLib/Channel/AbstractChannel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,11 @@ protected function createMessage($propertyReader, $contentReader)
299299
->load_properties($propertyReader)
300300
->setBodySize($contentReader->read_longlong());
301301

302-
while (bccomp($message->getBodySize(), $bodyReceivedBytes, 0) == 1) {
302+
while ($message->getBodySize() > $bodyReceivedBytes) {
303303
list($frame_type, $payload) = $this->next_frame();
304304

305305
$this->validate_body_frame($frame_type);
306-
$bodyReceivedBytes = bcadd($bodyReceivedBytes, mb_strlen($payload, 'ASCII'), 0);
306+
$bodyReceivedBytes += mb_strlen($payload, 'ASCII');
307307

308308
if (is_int($this->maxBodySize) && $bodyReceivedBytes > $this->maxBodySize ) {
309309
$message->setIsTruncated(true);

PhpAmqpLib/Wire/AMQPDecimal.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace PhpAmqpLib\Wire;
33

44
use PhpAmqpLib\Exception\AMQPOutOfBoundsException;
5+
use phpseclib\Math\BigInteger;
56

67
/**
78
* AMQP protocol decimal value.
@@ -42,7 +43,10 @@ public function __construct($n, $e)
4243
*/
4344
public function asBCvalue()
4445
{
45-
return bcdiv($this->n, bcpow(10, $this->e));
46+
$n = new BigInteger($this->n);
47+
$e = new BigInteger('1' . str_repeat('0', $this->e));
48+
list($q) = $n->divide($e);
49+
return $q->toString();
4650
}
4751

4852
/**

0 commit comments

Comments
 (0)