PHP Класс Money\Money

Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$amount string The money amount
$currency Currency The amount currency

Открытые методы

Метод Описание
__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

Приватные методы

Метод Описание
__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

Описание методов

__callStatic() публичный статический метод

$fiveDollar = Money::USD(500);
public static __callStatic ( string $method, array $arguments ) : Money
$method string
$arguments array
Результат Money

add() публичный метод

Returns a new Money object that represents the sum of this and another Money object
public add ( Money $addend ) : Money
$addend Money
Результат Money

amount() публичный метод

Returns the value represented by this Money object
public amount ( ) : string
Результат string

convertTo() публичный метод

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
Результат Money

currency() публичный метод

Returns the currency of this Money object
public currency ( ) : Currency
Результат Currency

divideBy() публичный метод

Returns a new Money object that represents the divided value by the given factor
public divideBy ( numeric $divisor ) : Money
$divisor numeric
Результат Money

equals() публичный метод

Checks whether the value represented by this object equals to the other
public equals ( Money $other ) : boolean
$other Money
Результат boolean

fromAmount() публичный статический метод

Creates a Money object from its amount and currency
public static fromAmount ( numeric $amount, Currency $currency ) : Money
$amount numeric
$currency Currency
Результат Money

hasSameCurrencyAs() публичный метод

Checks whether a Money has the same Currency as this
public hasSameCurrencyAs ( Money $other ) : boolean
$other Money
Результат boolean

isGreaterThan() публичный метод

Checks whether the value represented by this object is greater than the other
public isGreaterThan ( Money $other ) : boolean
$other Money
Результат boolean

isGreaterThanOrEqualTo() публичный метод

public isGreaterThanOrEqualTo ( Money $other ) : boolean
$other Money
Результат boolean

isLessThan() публичный метод

Checks whether the value represented by this object is less than the other
public isLessThan ( Money $other ) : boolean
$other Money
Результат boolean

isLessThanOrEqualTo() публичный метод

public isLessThanOrEqualTo ( Money $other ) : boolean
$other Money
Результат boolean

isNegative() публичный метод

Checks if the value represented by this object is negative
public isNegative ( ) : boolean
Результат boolean

isPositive() публичный метод

Checks if the value represented by this object is positive
public isPositive ( ) : boolean
Результат boolean

isZero() публичный метод

Checks if the value represented by this object is zero
public isZero ( ) : boolean
Результат boolean

multiplyBy() публичный метод

Returns a new Money object that represents the multiplied value by the given factor
public multiplyBy ( numeric $multiplier ) : Money
$multiplier numeric
Результат Money

round() публичный метод

Rounds this Money to another scale
public round ( integer $scale ) : Money
$scale integer
Результат Money

subtract() публичный метод

Returns a new Money object that represents the difference of this and another Money object
public subtract ( Money $subtrahend ) : Money
$subtrahend Money
Результат Money

Описание свойств

$amount защищенное свойство

The money amount
protected string $amount
Результат string

$currency защищенное свойство

The amount currency
protected Currency,money $currency
Результат Currency