Ether Binder
Set of utilities for interacting with Ethereum and it's smart contracts with PHP, with generating ABI bindings and Ethereum-related types
Loading...
Searching...
No Matches
M8B\EtherBinder\Utils\OOGmp Class Reference
Inheritance diagram for M8B\EtherBinder\Utils\OOGmp:
M8B\EtherBinder\Common\HashSerializable

Public Member Functions

 __construct (null|string|GMP $number=null, ?int $base=null)
 
 toInt ()
 
 toString (bool $hex=false, bool $no0xHex=false, ?int $lpad0=null)
 
 toBin (?int $lpad0=null)
 
 __toString ()
 
 raw ()
 
 eq (OOGmp|int|GMP $b)
 
 gt (OOGmp|int|GMP $b)
 
 lt (OOGmp|int|GMP $b)
 
 ge (OOGmp|int|GMP $b)
 
 le (OOGmp|int|GMP $b)
 
 greaterThan (OOGmp|int|GMP $b)
 
 lessThan (OOGmp|int|GMP $b)
 
 lessOrEqual (OOGmp|int|GMP $b)
 
 greaterOrEqual (OOGmp|int|GMP $b)
 
 equal (OOGmp|int|GMP $b)
 
 add (OOGmp|int|GMP $b)
 
 sub (OOGmp|int|GMP $b)
 
 mul (OOGmp|int|GMP $b)
 
 div (OOGmp|int|GMP $b)
 
 max (OOGmp|int|GMP $b)
 
 min (OOGmp|int|GMP $b)
 
 mod (OOGmp|int|GMP $b)
 
 toHex ()
 
 toBin ()
 

Static Public Member Functions

static wrap (GMP $raw)
 
static fromHex (string $hex)
 
static fromBin (string $bin)
 

Detailed Description

OOGmp is a utility class that wraps PHP's GMP library for working with arbitrary-size integers. It provides an easy-to-use, object-oriented API for Ethereum-related operations and offers a chainable arithmetic operations API.

Arithmetic Functions: The class provides basic arithmetic operations like addition (add), subtraction (sub), multiplication (mul), and division (div). These methods support automatic type normalization, allowing you to pass in OOGmp|int|GMP as arguments.

Comparison Functions: Standard comparison operations are included, such as eq (equals), lt (less than), gt (greater than), etc. Aliases are also available, like eq - equal. These functions also support automatic type normalization.

Author
DubbaThony

Constructor & Destructor Documentation

◆ __construct()

M8B\EtherBinder\Utils\OOGmp::__construct ( null|string|GMP $number = null,
?int $base = null )

Initializes a new OOGmp object.

Parameters
null | string | GMP$numberThe initial number value as null, string, or GMP object.
int | null$baseThe base for string input. Defaults attempts to guess, if $number has 0x prefix, it defaults to 16, otherwise if it has any of a-f characters, it defaults to 16, otherwise it defaults to 10. Be very cautions when relying on that detection as non-0x-prefixed hex that happens to not have any a-f will be mistreated as base = 10.

Member Function Documentation

◆ fromBin()

static M8B\EtherBinder\Utils\OOGmp::fromBin ( string $bin)
static

Static alias to constructor to fulfil HashSerializable interface

Parameters
string$bin
Returns
OOGmp

Implements M8B\EtherBinder\Common\HashSerializable.

◆ fromHex()

static M8B\EtherBinder\Utils\OOGmp::fromHex ( string $hex)
static

Static alias to constructor to fulfil HashSerializable interface

Parameters
string$hex
Returns
OOGmp

Implements M8B\EtherBinder\Common\HashSerializable.

◆ raw()

M8B\EtherBinder\Utils\OOGmp::raw ( )

Returns the raw GMP object.

Returns
GMP The internal GMP object.

◆ toBin() [1/2]

M8B\EtherBinder\Common\HashSerializable::toBin ( )
inherited

Implemented in M8B\EtherBinder\Common\Hash.

◆ toBin() [2/2]

M8B\EtherBinder\Utils\OOGmp::toBin ( ?int $lpad0 = null)

Converts the internal GMP number to a binary string.

Parameters
int | null$lpad0Number of zeros to pad on the left.
Returns
string The binary string representation of the GMP number.
Exceptions
InvalidHexException

◆ toHex()

M8B\EtherBinder\Utils\OOGmp::toHex ( )

Alias to toString() to fulfil HashSerializable interface

Returns
string

Implements M8B\EtherBinder\Common\HashSerializable.

◆ toInt()

M8B\EtherBinder\Utils\OOGmp::toInt ( )

Converts the internal GMP number to an integer.

Returns
int The integer representation of the GMP number.
Exceptions
EthBinderRuntimeExceptionIf the GMP number is larger than PHP_INT_MAX.

◆ toString()

M8B\EtherBinder\Utils\OOGmp::toString ( bool $hex = false,
bool $no0xHex = false,
?int $lpad0 = null )

Converts the internal GMP number to a string.

Parameters
bool$hexIf true, returns a hexadecimal string. Otherwise, returns a decimal string.
bool$no0xHexIf true and $hex is true, omits the "0x" prefix.
int | null$lpad0Number of zeros to pad on the left.
Returns
string The string representation of the GMP number.

◆ wrap()

static M8B\EtherBinder\Utils\OOGmp::wrap ( GMP $raw)
static

Wraps a raw GMP object into an OOGmp instance.

Parameters
GMP$rawThe GMP object to be wrapped.
Returns
OOGmp The new OOGmp instance wrapping the given GMP object.

The documentation for this class was generated from the following file: