PHP Class Money\Money

显示文件 Open project: ulabox/money Class Usage Examples

Protected Properties

Property Type Description
$amount string The money amount
$currency Currency The amount currency

Public Methods

Method Description
__callStatic ( string $method, array $arguments ) : Money Convenience factory method for a Money object
add ( Money $addend ) : Money Returns a new Money object that represents the sum of this and another Money object
amount ( ) : string Returns the value represented by this Money object
convertTo ( Currency $targetCurrency, numeric $conversionRate ) : Money Converts the currency of this Money object to a given target currency with a given conversion rate
currency ( ) : Currency Returns the currency of this Money object
divideBy ( numeric $divisor ) : Money Returns a new Money object that represents the divided value by the given factor
equals ( Money $other ) : boolean Checks whether the value represented by this object equals to the other
fromAmount ( numeric $amount, Currency $currency ) : Money Creates a Money object from its amount and currency
hasSameCurrencyAs ( Money $other ) : boolean Checks whether a Money has the same Currency as this
isGreaterThan ( Money $other ) : boolean Checks whether the value represented by this object is greater than the other
isGreaterThanOrEqualTo ( Money $other ) : boolean
isLessThan ( Money $other ) : boolean Checks whether the value represented by this object is less than the other
isLessThanOrEqualTo ( Money $other ) : boolean
isNegative ( ) : boolean Checks if the value represented by this object is negative
isPositive ( ) : boolean Checks if the value represented by this object is positive
isZero ( ) : boolean Checks if the value represented by this object is zero
multiplyBy ( numeric $multiplier ) : Money Returns a new Money object that represents the multiplied value by the given factor
round ( integer $scale ) : Money Rounds this Money to another scale
subtract ( Money $subtrahend ) : Money Returns a new Money object that represents the difference of this and another Money object

Private Methods

Method Description
__construct ( string $amount, Currency $currency )
assertNumeric ( numeric $value ) Asserts that a value is a valid numeric string
assertSameCurrencyAs ( Money $other ) Asserts that a Money has the same currency as this
compareTo ( Money $other ) : integer Returns an integer less than, equal to, or greater than zero if the value of this object is considered to be respectively less than, equal to, or greater than the other
compareTo0 ( ) : integer Returns an integer less than, equal to, or greater than zero if the value of this object is considered to be respectively less than, equal to, or greater than 0
newInstance ( string $amount ) : Money Returns a new Money instance based on the current one

Method Details

__callStatic() public static method

$fiveDollar = Money::USD(500);
public static __callStatic ( string $method, array $arguments ) : Money
$method string
$arguments array
return Money

add() public method

Returns a new Money object that represents the sum of this and another Money object
public add ( Money $addend ) : Money
$addend Money
return Money

amount() public method

Returns the value represented by this Money object
public amount ( ) : string
return string

convertTo() public method

Converts the currency of this Money object to a given target currency with a given conversion rate
public convertTo ( Currency $targetCurrency, numeric $conversionRate ) : Money
$targetCurrency Currency
$conversionRate numeric
return Money

currency() public method

Returns the currency of this Money object
public currency ( ) : Currency
return Currency

divideBy() public method

Returns a new Money object that represents the divided value by the given factor
public divideBy ( numeric $divisor ) : Money
$divisor numeric
return Money

equals() public method

Checks whether the value represented by this object equals to the other
public equals ( Money $other ) : boolean
$other Money
return boolean

fromAmount() public static method

Creates a Money object from its amount and currency
public static fromAmount ( numeric $amount, Currency $currency ) : Money
$amount numeric
$currency Currency
return Money

hasSameCurrencyAs() public method

Checks whether a Money has the same Currency as this
public hasSameCurrencyAs ( Money $other ) : boolean
$other Money
return boolean

isGreaterThan() public method

Checks whether the value represented by this object is greater than the other
public isGreaterThan ( Money $other ) : boolean
$other Money
return boolean

isGreaterThanOrEqualTo() public method

public isGreaterThanOrEqualTo ( Money $other ) : boolean
$other Money
return boolean

isLessThan() public method

Checks whether the value represented by this object is less than the other
public isLessThan ( Money $other ) : boolean
$other Money
return boolean

isLessThanOrEqualTo() public method

public isLessThanOrEqualTo ( Money $other ) : boolean
$other Money
return boolean

isNegative() public method

Checks if the value represented by this object is negative
public isNegative ( ) : boolean
return boolean

isPositive() public method

Checks if the value represented by this object is positive
public isPositive ( ) : boolean
return boolean

isZero() public method

Checks if the value represented by this object is zero
public isZero ( ) : boolean
return boolean

multiplyBy() public method

Returns a new Money object that represents the multiplied value by the given factor
public multiplyBy ( numeric $multiplier ) : Money
$multiplier numeric
return Money

round() public method

Rounds this Money to another scale
public round ( integer $scale ) : Money
$scale integer
return Money

subtract() public method

Returns a new Money object that represents the difference of this and another Money object
public subtract ( Money $subtrahend ) : Money
$subtrahend Money
return Money

Property Details

$amount protected_oe property

The money amount
protected string $amount
return string

$currency protected_oe property

The amount currency
protected Currency,money $currency
return Currency